]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex2_59.rkt
solutions to 4.35, 4.36 and 4.37
[sicp.git] / src / sicp / ex2_59.rkt
1 #lang racket
2
3 (require "ch2_3_3.rkt")
4
5 (define (union-set set1 set2)
6   (cond ((null? set1) set2)
7         ((null? set2) set1)
8         ((element-of-set? (car set1) set2) (union-set (cdr set1) set2))
9         (else (cons (car set1) (union-set (cdr set1) set2)))))
10
11  (union-set '(1 2 3 4) '(5 6 7 8))
12  (union-set '(1 2 3 4) '(1 2 3 4))
13  (union-set '(1 2 3 4) '(1 2 7 8))