;; gather-green-eyed: person -> list-of-string ;; consumes a person and produces a list of the names of all people in the person's tree ;; who have green eyes (define (gather-green-eyed aper) (cond [(symbol=? 'green (person-eye aper)) (cons (person-name aper) (green-list (person-children aper)))] [else (green-list (person-children aper))])) ;; green-list: list-of-person -> list-of-string ;; consumes a list of persons and produces a list of the names of all people in the list ;; (and their descendants) who have green eyes (define (green-list alop) (cond [(empty? alop) empty ] [(cons? alop) (append (gather-green-eyed (first alop)) (green-list (rest alop)) ) ])) ;; test (check-expect (gather-green-eyed SusanTree) (list "Joe" "Hank")) ;; people-with-kids: person -> list-of-string ;; consumes a person and produces a list of the names of everyone in the person's tree who have children (define (people-with-kids aper) (cond [(cons? (person-children aper)) (cons (person-name aper) (kids-with-kids (person-children aper)))] [else empty])) ;; kids-with-kids: list-of-person -> list-of-string ;; consumes alist of person and produces the names of everyone in the list who has children (define (kids-with-kids alop) (cond [(empty? alop) empty ] [(cons? alop) (append (people-with-kids (first alop)) (kids-with-kids (rest alop) ) )])) (check-expect (people-with-kids SusanTree) (list "Susan" "Helen")) ;; find-person: string person -> person OR false ;; consumes a name and a person and produces the person in the tree with the given name, or ;; produces false if the named person is not in the tree (define (find-person name aper) (cond [(string=? name (person-name aper)) aper] [else (find-in-list name (person-children aper))])) ;; find-in-list: string list-of-person -> person OR false ;; consumes a list of person and returns the person in the list with the given name, or returns false if ;; named person doesn't exist (define (find-in-list name alop) (cond [(empty? alop) false ] [(cons? alop) (cond [(person? (find-person name (first alop))) (find-person name (first alop))] [else (find-in-list name (rest alop) ) ]) ])) (check-expect (find-person "Joe" SusanTree) (make-person "Joe" 1938 'green empty)) (check-expect (find-person "Sally" SusanTree) false)