;; A ftnode is either ;; - 'unknown or ;; - (make-person string number symbol ftnode ftnode) (define-struct person (name year eye mother father)) ;; Example (define MaryTree (make-person "Mary" 1980 'blue (make-person "Ann" 1960 'green 'unknown (make-person "Fred" 1936 'blue 'unknown 'unknown)) (make-person "Joe" 1960 'blue 'unknown 'unknown))) ;; update-year: ftnode string number -> ftnode ;; consumes a family tree node, a name, and a birth year. The function ;; produces a ftnode the same as the original except that the birth year ;; of the named person is now the given birth year (define (update-year aft name year) (cond [(symbol? aft) aft] [(person? aft) (cond [(string=? (person-name aft) name) (make-person (person-name aft) year (person-eye aft) (person-mother aft) (person-father aft))] [else (make-person (person-name aft) (person-year aft) (person-eye aft) (update-year (person-mother aft) name year) (update-year (person-father aft) name year))])])) ;; test (check-expect (update-year MaryTree "Ann" 1958) (make-person "Mary" 1980 'blue (make-person "Ann" 1958 'green 'unknown (make-person "Fred" 1936 'blue 'unknown 'unknown)) (make-person "Joe" 1960 'blue 'unknown 'unknown))) (check-expect (update-year MaryTree "Bruce" 1939) MaryTree) (check-expect (update-year 'unknown "Sally" 1965) 'unknown) ;; gather-blue-eyed: ftnode -> list-of-string ;; consumes a family tree node and produces a list of the names of all ;; people in the tree who have blue eyes (define (gather-blue-eyed aft) (cond [(symbol? aft) empty] [(person? aft) (cond [(symbol=? 'blue (person-eye aft)) (append (list (person-name aft)) (gather-blue-eyed (person-mother aft)) (gather-blue-eyed (person-father aft)))] [else (append (gather-blue-eyed (person-mother aft)) (gather-blue-eyed (person-father aft)))])])) ;; test (check-expect (gather-blue-eyed 'unknown) empty) (check-expect (gather-blue-eyed MaryTree) (list "Mary" "Fred" "Joe"))