Skip to content

Instantly share code, notes, and snippets.

@yakreved
Created August 29, 2013 12:14
Show Gist options
  • Save yakreved/6377291 to your computer and use it in GitHub Desktop.
Save yakreved/6377291 to your computer and use it in GitHub Desktop.
sicp 2.61
(define (element-of-set? x set)
(cond ((null? set) #f)
((= x (car set)) #t)
((< x (car set)) #f)
(else (element-of-set? x (cdr set)))))
(define a '(1 2 4 6))
(define b '(3 4 5 6 7 8))
(element-of-set? 3 a)
(element-of-set? 5 a)
(define (adjoin-set x set)
(cond ((null? set) (cons x '()))
((= x (car set)) set)
((< x (car set)) (cons x set))
((> x (car set)) (cons (car set)
(adjoin-set x (cdr set))))))
(adjoin-set 3 a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment