data-centric-computing / dcic-public

Repository for (for now) filing bug reports about DCIC.
21 stars 2 forks source link

[DCIC Book]: 7.1.1.2 Problems in two implementations of `grandparents-of` #76

Closed muzimuzhi closed 9 months ago

muzimuzhi commented 1 year ago

Contact Details

No response

Which Web page has the problem?

https://dcic-world.org/2023-02-21/trees.html#%28part._.Computing_.Grandparents_from_an_.Ancestry_.Table%29

What's the problem?

In the first implementation of grandparents-of function in sec. 7.1.1.2,

In the second implementation of graendparents-of function in the same section,

In total,

diff --git a/old.arr b/new.arr
index aa866fd..c598594 100644
--- a/old.arr
+++ b/new.arr
@@ -1,22 +1,23 @@
-fun grandparents-of(anc-table: Table, person: String) -> List[String]:
+fun grandparents-of(anc-table :: Table, person :: String) -> List<String>:
   doc: "compute list of known grandparents in the table"
   # glue together lists of mother's parents and father's parents
   plist = parents-of(anc-table, person) # gives a list of two names
   parents-of(anc-table, plist.first) +
     parents-of(anc-table, plist.rest.first)
 where:
-  grandparents("Anna") is [list: "Laura", "John"]
-  grandparents("Laura") is [list:]
-  grandparents("Kathi") is [list:]
+  grandparents-of(ancestors, "Anna") is [list: "Ellen", "Bill"]
+  grandparents-of(ancestors, "John") is [list: ]
+  grandparents-of(ancestors, "Laura") is [list: ]
+  grandparents-of(ancestors, "Kathi") raises "No such person"
 end

-fun grandparents-of(anc-table :: Table, name :: String) -> List<String>:
+fun grandparents-of(anc-table :: Table, person :: String) -> List<String>:
   doc: "compute list of known grandparents in the table"
   # glue together lists of mother's parents and father's parents
-  plist = parents-of(anc-table, name) # gives a list of two names
-  if plist.length == 2:
+  plist = parents-of(anc-table, person) # gives a list of two names
+  if plist.length() == 2:
     parents-of(anc-table, plist.first) + parents-of(anc-table, plist.rest.first)
-  else if plist.length == 1:
+  else if plist.length() == 1:
     parents-of(anc-table, plist.first)
   else: empty
   end

What browser are you seeing the problem on?

Chrome

kfisler commented 9 months ago

Fixed (and sorry for the delay). Thanks for the detailed set of corrections!

kfisler commented 9 months ago

eb3c2dbdfa41e48f89fba17dcf9e590298bce39b