Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.78 KB | None | 0 0
  1. ; FamilyTree -> Names
  2. ; extract the names of all mothers and fathers from a family tree
  3. (define (names-of-ancestors family-tree)
  4.   (match family-tree
  5.     [(person name mother father)
  6.      (local [(define (append-parent parent selector)
  7.                (local [(define (select-parents parent) (selector (names-of-ancestors parent)))]
  8.                  (make-names (append (if (person? parent)
  9.                                          (list (person-name parent))
  10.                                          (list))
  11.                                      (get-parents mother))
  12.                              (get-parents father))))]
  13.        (make-names (append-parent mother names-mothers)
  14.                    (append-parent father names-fathers)))]
  15.     [#false
  16.      (make-names (list) (list))]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement