exercise-60.scm (870B)
1 ;; Exercise 2.60 XXX 2 3 (define (exercise-2.60) 4 ;; I don't get it. Am I supposed to let these sets explode by just appending 5 ;; more and more stuff to them? 6 7 (define (element-of-set? x set) 8 (cond 9 ((null? set) #f) 10 ((equal? x (car set)) #t) 11 (else (element-of-set? x (cdr set))))) 12 13 (define (adjoin-set x set) 14 (cons x set)) 15 16 (define (union-set set1 set2) 17 (append set1 set2)) 18 19 (define (intersection-set set1 set2) 20 (cond 21 ((or (null? set1) 22 (null? set2)) '()) 23 ((equal? (car set1) (element-of-set? (car set1) 24 set2)) 25 (adjoin-set (car set1) 26 (intersection-set (cdr set1) 27 set2))) 28 (else (intersection-set (cdr set1) 29 set2)))) 30 31 (test-begin "2.60") 32 (test-end "2.60")) 33 34 (exercise-2.60) 35