Skip to content

Instantly share code, notes, and snippets.

@dargonforce
Created January 26, 2017 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dargonforce/e077a76047fe6ca05fca9432fa577138 to your computer and use it in GitHub Desktop.
Save dargonforce/e077a76047fe6ca05fca9432fa577138 to your computer and use it in GitHub Desktop.
;;; is 'lat' a set
(define set? (lambda (lat)
(cond
((null? lat) #t)
(else
(cond
((member? (cdr lat) (car lat)) #f)
(else (set? (cdr lat))))))))
;;; is 'a' a member of 'lat'
(define member? (lambda (a lat)
(cond
((null? lat) #f)
(else
(or
(eq? (car lat) a)
(member? a
(cdr lat)))))))
;;; is 'a' a subset of 'b'
;;; assumes 'a' and 'b' are both sets
(define subset? (lambda (a b)
(cond
((null? a) #t)
((member? (car a) b)
(subset? (cdr a) b))
(else #f))))
;;; redefinition of subset?, using or's and and's instead of cond
(define subset? (lambda (a b)
(or
(null? a)
(and
(member? (car a) b)
(subset? (cdr a) b)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment