General:. The #set
object is a skip list (behaves like a balanced binary tree). The compare
function scrutinizes key/value pairs holding them unique. In that regard it is
just like the #dict object. However, the #set does not allow
you to set the value. It does it automatically with integers beginning with 1
and increasing to 2^31. Multiple assignments of the same key to the
set are ignored. For Glee syntax, you must supply a value.
Glee ignores that value. Indexing into a set by key returns the
automatically assigned integer value. Indexing into a set by value returns the
associated key. You cannot use an number as a key in a set. Sets are good for
enumerating things and giving them exclusive ID's.
Simple insertion and display:
This illustrates how keys are entered into a set. The :seq method
returns the whole set as a sequence of couplets. It is useful for illustrating
the concepts and for testing but would not likely find use for large sets.
Access (indexing): When you
access (index) a set by key, you are returned the assigned integer value for
that key. The result is always a sequence. If you supply more than one key (as
in this example), you will index out the resulting sequence of assigned values
in correspondence to the order in which you supplied the keys. If you index by
the supplied integer values, the corresponding keys are returned. A non-value
(NV) object is returned when keys or assigned values are not found.
Remove ( ~ ): For
removal, a key is supplied. The "without" operator ( ~ )
leaves the set without the key/assigned value pair. As with dictionaries, it is
illogical to return the entire set as the result (it could be huge). Thus, the
removals are done "in place".