;; A person is (make-person string number symbol list-of-person) (define-struct person (name year eye kids)) ;; A list-of-person is ;; - empty, or ;; - (cons person list-of-person) ;; people-with-kids : person -> list-of-string ;; consumes a person and produces list of names of all people in their family ;; tree who have children (define (people-with-kids aper) (cond [(cons? (person-kids aper)) (cons (person-name aper) (kids-with-kids (person-kids aper)))] [else empty])) ;; kids-with-kids : list-of-person -> list-of-string ;; consumes list of people and produces names of all descendents of those people ;; who have children (define (kids-with-kids alop) (cond [(empty? alop) empty] [(cons? alop) (append (people-with-kids (first alop)) (kids-with-kids (rest alop)))])) ;;-------------------------------------------------------------------- ;; find-person : string person -> person OR false ;; consumes name and person and produces person with given name, or ;; false if person not in tree (define (find-person name aper) (cond [(string=? (person-name aper) name) aper] [else (find-in-list name (person-kids aper))])) ;; find-in-kids : string list-of-person -> person OR false ;; consume name and list of person and returns person with given name ;; from trees in the list or false if no such person (define (find-in-kids name alop) (cond [(empty? alop) false] [(cons? alop) (cond [(person? (find-person name (first alop))) (find-person name (first alop))] [else (find-in-kids name (rest alop))])])) ;;--------------------------------------------------------------------