Skip to content

Instantly share code, notes, and snippets.

@vishesh
Last active August 29, 2015 14:13
Show Gist options
  • Save vishesh/2c2ead9db81c8c197ecf to your computer and use it in GitHub Desktop.
Save vishesh/2c2ead9db81c8c197ecf to your computer and use it in GitHub Desktop.
; Purely functional implementation of Set data structure
(define set-init
(lambda (x) #false))
(define (set-add set x)
(lambda (y)
(if (= x y)
#true
(set y))))
(define (set-union set1 set2)
(lambda (y)
(or (set1 y) (set2 y))))
(define (set-intersect set1 set2)
(lambda (y)
(and (set1 y) (set2 y))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment