Sets

Set Operations

FunctionDescription
set.from-list(xs)Create a set from list xs of primitive values
set.to-listReturn sorted list of elements in set s
set.addAdd element e to set s
set.removeRemove element e from set s
set.contains?True if set s contains element e
set.sizeReturn number of elements in set s
set.empty?(s)True if set s has no elements
set.unionReturn union of sets a and b
set.intersectReturn intersection of sets a and b
set.diffReturn elements in set a that are not in set b
(∅)The empty set
s: set.from-list([1, 2, 3, 2, 1])
# s contains {1, 2, 3} (duplicates removed)

Set Algebra

a: set.from-list([1, 2, 3])
b: set.from-list([2, 3, 4])
u: set.union(a, b) set.to-list       # [1, 2, 3, 4]
i: set.intersect(a, b) set.to-list   # [2, 3]
d: set.diff(a, b) set.to-list        # [1]