Created
August 29, 2013 01:13
-
-
Save yakreved/6373256 to your computer and use it in GitHub Desktop.
sicp 2.60
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
(define (element-of-set? x set) | |
(cond ((null? set) #f) | |
((= x (car set)) #t) | |
(else (element-of-set? x (cdr set))))) | |
(define a '(1 2 3 4 6 6)) | |
(define b '(3 4 5 6 2)) | |
(element-of-set? 3 a) | |
(element-of-set? 5 a) | |
(define (adjoin-set x set) | |
(cons x set)) | |
(define (union-set x y) | |
(cond ((null? x) y) | |
(else (union-set (cdr x) (cons (car x) y))) | |
) | |
) | |
(define (intersection-set set1 set2) | |
(cond ((or (null? set1) (null? set2)) '()) | |
((element-of-set? (car set1) set2) | |
(cons (car set1) | |
(intersection-set (cdr set1) set2))) | |
(else (intersection-set (cdr set1) set2)))) | |
(union-set a b) | |
(intersection-set a b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment