;; the book example Ch. 14 ;; a child structure represents a person ;; father and mother are "child" structures that ;; represent the person's parents ;; or empty if there is no data on a parent ;; name is a symbol (the person's name) ;; date is a positive integer (year of birth) ;; eyes is a symbol that represents the color of the eyes (define-struct child (father mother name date eyes)) ;; Oldest Generation: (define Carl (make-child empty empty 'Carl 1926 'green)) (define Bettina (make-child empty empty 'Bettina 1926 'green)) ;; Middle Generation: (define Adam (make-child Carl Bettina 'Adam 1950 'yellow)) (define Dave (make-child Carl Bettina 'Dave 1955 'black)) (define Eva (make-child Carl Bettina 'Eva 1965 'blue)) (define Fred (make-child empty empty 'Fred 1966 'pink)) ;; Youngest Generation: (define Gustav (make-child Fred Eva 'Gustav 1988 'brown)) ;; blue-eyed-ancestor? : family tree node (ftn) -> boolean ;; to determine whether a-ftree contains a child ;; structure with 'blue in the eyes field (define (blue-eyed-ancestor? a-ftree) (cond ;; fill in the rest )) (check-expect (blue-eyed-ancestor? Carl) false) (check-expect (blue-eyed-ancestor? Gustav) true) ;; count-persons: family tree node -> integer ;; consumes a family tree node ;; counts how many people are there in the known family tree ;; rooted in the node, counting the person at the node itself (check-expect (count-persons Adam) 3) (check-expect (count-persons Gustav) 5) ;; eye-colors: family tree node -> list of symbols ;; consumes a family tree node and produces a list of all eye colors ;; in the tree. An eye color may occur more than once in the list. ;; note that check-expect may need to be adjusted if the list elements ;; are the same but in a different order (check-expect (eye-colors Adam) (list 'yellow 'green 'green)) (check-expect (eye-colors Gustav) (list 'brown 'blue 'green 'green 'pink))