You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
3 weeks ago | |
---|---|---|
README.md | 1 year ago | |
main.slo | 3 weeks ago | |
module.json | 1 year ago |
README.md
sets
sets - a module for operating on Sets
api
initialize, verify, and check equality
(set [input: list]) => list
(set? [input: list]) => bool
(set-equal? [set1: set] [set2: set]) => bool
subset and proper-subset checking
(subset? [sub: set] [super: set]) => bool
(proper-subset? [sub: set] [super: set]) => bool
set functions
(intersection [set1: set] [set2: set]) => set
(union [set1: set] [set2: set]) => set
(rel-compl [set1: set] [set2: set]) => set
(sym-diff [set1: set] [set2: set]) => set
(cartesian [set1: set] [set2: set]) => set
todo
(power-set [input: set]) => set
(n-cartesian [set1: set] [set2: set] [[setN: set...]]) => set
usage
; some lists for us to mess with
(define uniq1 [1 2 3])
(define uniq2 [3 1 5])
(define dups [2 3 4 3 5])
(set uniq1) ; => [1 2 3] (no change)
(set dups) ; => [2 3 4 5] (sets don't contain dups)
; sets are just lists without dups
(set? uniq1) ; => #t
(set? dups) ; => #f
; sets have no "order", so equality is based only on values
(set-equal? uniq1 uniq1) ; => #t
(set-equal? uniq1 uniq2) ; => #f
(set-equal? uniq1 [3 2 1]) ; => #t
; subsets have all members of the super set
; proper subsets are subsets that are not `set-equal?` to the super set
(subset? uniq1 uniq1) ; => #t
(subset? [1 3] uniq1) ; => #t
(subset? uniq1 uniq2) ; => #f
(proper-subset? uniq1 uniq1) ; => #f
(proper-subset? [1 3] uniq1) ; => #t
(proper-subset? uniq1 uniq2) ; => #f
; let's do set math
(intersection uniq1 uniq2) ; => [1 3]
(union uniq1 uniq2) ; => [1 2 3 5]
(rel-compl uniq1 uniq2) ; => [2]
(sym-diff uniq1 uniq2) ; => [2 5]
(cartesian uniq1 uniq2) ; => [[1 3] [1 1] [1 5] [2 3] [2 1] [2 5] [3 3] [3 1] [3 5]]