Skip to content

Instantly share code, notes, and snippets.

@zestime
Created December 19, 2014 08:19
Show Gist options
  • Save zestime/75cb139755c35387ce1a to your computer and use it in GitHub Desktop.
Save zestime/75cb139755c35387ce1a to your computer and use it in GitHub Desktop.
; 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