Comp 200 Lecture 11
Family Trees

Fri 08 Feb 2002

Family Trees

(perhaps better called "ancestor trees").
Draw some examples:
?     ?     ?   ?  ?      ?
 \   /       \ /    \    /
'jackie      'mona  'abraham
 (1926)  ?   (1929) (1920)
    \   /       \   /
   'marge      'homer
    (1956)      (1955)
        \      /
         'bart
         (1979)
Note: We don't know the name of Grampa Bouvier, marge's father, but he died in a roller-coaster accident.) (Birthdates fabricated, but names courtesy of springfield nuclear power plant's web site.) We know Abe was an enlisted man in WWII: his squad, the flying hellfish, found a a cache of stolen paintings, and they formed a tontine ("an investment plan in which participants buy shares in a common fund and recevie an annuity, with the entire fund going to the final survivor or to those who survive after a specified time. [Fr., after Lorenzo Tonti (1635-90?), Naples-born French banker]. Source: American Heritage College Dictionary)
Some simpler family trees:
?      ?
 \    /
 'jackie
  (1926)
and
?     ?
 \   /
'jackie   
 (1926)  ?
    \   /
   'marge
   (1958)
What might be considered the simplest possible family tree?

Definition: a FamTree is Note: Be sure to differentiate the two different concepts: "child", which is somebody whose name we know, vs "FamTree", which might be a child or an unknown. We used ? above to denote unknown.

Examples:

Aside: In Computer Science, trees of this pattern are called binary trees. Can you guess why?
Looking for a parallel to lists:
purpose list functions tree functions (provided to you)
terminal values empty unknown
build one out of smaller parts cons: any, list --> list make-child: symbol, FamTree, FamTree, number --> child
select parts of a compound item
first : cons --> any
rest : cons --> list
child-name : child --> symbol
child-ma: child --> FamTree
child-pa : child --> FamTree
child-birthyear : child --> number
recognizers (predicate functions)
list? : any --> boolean
empty? : any --> boolean
cons? : any --> boolean
FamTree? : any --> boolean
unknown? : any --> boolean
child? : any --> boolean
We will define them. In the above table, I distinguish between structure values and the functions that create those structures. For instance, make-unknown and make-child describe the functions used to create an unknown structure and a child structure, respectively. In the data definition, we used make-X along with the structure parameters (variables), to talk about the structures themselves, not the functions that create them. This is a bit confusing to understand at first.

Currently, these functions aren't built-in to DrScheme. We will define them ourseleves. We represent FamTrees using structures.

#|
  We will define the following Family Tree functions: 
  make-child, child-name, child-ma, child-pa, child-birthyear,
  child?, unknown?, and FamTree? 
|#

;;remember, this structure definition will define the following functions:
;;  make-child, child-ma, child-pa, child-birthyear, child?
(define-struct child (name ma pa birthyear))

;;and this defines make-unknown and unknown?
(define-struct unknown ())

(define (FamTree? exp)
    (or (unkown? exp) (child? exp)))