Finite Sets

A finite set can be created with a pair of braces with all the set members in between and separated by commas.

colors = {"red", "orange", "yellow", "green", "blue", "purple"}
faces = {1, 2, 3, 4, 5, 6}

To test if a value x is member of a set s, one can use

   x (- s
or
   x in s
or
   s(x)
or
   s * x
If x is a member of s, all of the above will return non-zero; otherwise 0.

To add a new member to a set, use

s.add(m)
To remove a member from a set, use
s.remove(m)

The k-th element of a set can be extracted using

s[k]
However, the order of the members is not a property of the set. Therefore if s[1] is not equal to t[1], it doesn't imply that s does not equal t. Providing the indexing function is for the purpose of looping over the whole set. Note also that set member can not be added or updated using the indexing expression.



oz 2009-12-22