Sets are surrounded by the
brace symbols {
, }
.1.2
> empty := {}; # this set is empty empty := {} > FirstSet := {1, 1, 2, 2, 3, 3, 3}; FirstSet := {1,2,3} > SecondSet := {1, 2, 3}; SecondSet := {1,2,3}The sets FirstSet and SecondSet are equal since both contain exactly the elements 1, 2, 3.
> ascend := { 0, 5, 10, 15, 20 }; ascend := {0,5,10,15,20} > descend := { 20, 15, 10, 5, 0 }; descend := {0,5,10,15,20}Again, ascend and descend are equal because sets are unordered.
We can perform several operations on objects of this type including union, intersection, member, subset and minus. All of these operations correspond to the standard mathematical definitions.
> cdn := {'beaver', 'moose', 'grizzlie', 'loon', 'cow', 'deer'}: > ch := {'sheep', 'mouse', 'cow', 'deer'}: > intersect(cdn, ch); {cow,deer} > union(cdn, ch); {beaver,cow,deer,grizzlie,loon,moose,mouse,sheep} > member('grizzlie', ch); false > minus(cdn, ch); {beaver,grizzlie,loon,moose} > minus(ch, cdn); {mouse,sheep}We are not limited to placing only integer and string items in set structures. We could place any type of data we desire including other set and list objects. When each element of a set has the same type, we say that the set is homogeneous, otherwise we say that it is heterogeneous.
> mixed := {'salmon', {'coho', 'pink'}, 0, 'grizzlies', 1000, 'mosquitos'}; mixed := {0,1000,grizzlies,mosquitos,salmon,{coho,pink}}The set mixed contains objects of three types: string, integer, and set.