Created
December 19, 2014 08:19
-
-
Save zestime/75cb139755c35387ce1a to your computer and use it in GitHub Desktop.
This file contains 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
; No change, as same as before | |
(define (element-of-set? x set) | |
(cond ((null? set) false) | |
((equal? x (car set)) true) | |
(else (element-of-set? x (cdr set))))) | |
; Just use cons, don't need to use element-of-set anymore | |
(define (adjoin-set x set) | |
(cons x set)) | |
; as same as before | |
(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)))) | |
; changed, to use append is enough! | |
(define (union-set set1 set2) | |
(append set1 set2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment