Created
June 18, 2012 14:32
-
-
Save d11wtq/2948661 to your computer and use it in GitHub Desktop.
An exercise from The Seasoned Schemer. I really like the shape and feel of this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Given two sets, return a new set containing the unique members from each. | |
(define (union set1 set2) | |
(letrec | |
((union | |
(lambda (set) | |
(cond | |
((null? set) set2) | |
((member? (car set) set2) | |
(union (cdr set))) | |
(else | |
(cons (car set) | |
(union (cdr set))))))) | |
(member? | |
(lambda (a set) | |
(cond | |
((null? set) #f) | |
((equal? (car set) a) #t) | |
(else | |
(member? a (cdr set))))))) | |
(union set1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment