(define-struct person (name year eye mother father)) ;; a TreeNode is one of ;; false ;; no more data ;; (make-person String Natural String TreeNode TreeNode) ;; interp: ;; false means no more data in that part of the tree ;; for a person, name is the person's name ;; year is the year of birth ;; eye is the eye color ;; mother and father are the left and right subtrees (define MaryTree (make-person "Mary" 1980 "blue" (make-person "Ann" 1960 "green" false (make-person "Fred" 1936 "blue" false false)) (make-person "Joe" 1960 "blue" false false))) ;;; fcn-for-treenode: TreeNode -> ;;; ;(define (fcn-for-treenode atn) ; (cond [(false? atn) ] ; [(person? atn) (person-name atn) ; (person-year atn) ; (person-eye atn) ; (fcn-for-treenode (person-mother atn)) ; (fcn-for-treenode (person-father atn))])) ;; in-family?: String TreeNode -> Boolean ;; produces true if the tree contains a person with the given name (define (in-family? name atn) (cond [(false? atn) false ] [(person? atn) (or (string=? name (person-name atn)) (in-family? name (person-mother atn)) (in-family? name (person-father atn)))])) (check-expect (in-family? "Joe" false) false) (check-expect (in-family? "Joe" MaryTree) true) (check-expect (in-family? "Dennis" MaryTree) false)