Purpose: Definition of set functionality for an official extension.
This is a part of the Chart of proposed list functionality.
See also A set of Set operations.
Sometimes intersection and both onesided differences are required. A procedure computing them in parallel should be more efficient than doing it separately.
[AK] (Mar 20, 1999): The timing of the possible implementations proved me wrong, this procedure is not necessary.
LV: Are there other list oriented languages from whom we can 'borrow' set functionality ? Perl's idea of adopting concepts found in other languages, done in the spirit of perl, is one that could really work in Tcl as well. Mar 20, 1999
S1 ++ S2 set union; returns a set S1 ** S2 set intersection S1 -- S2 set difference *S1 the number of elements in S1 ?S returns a random element from S set(L) makes a set from a list member(S,x) fails if x is not a member of S, else returns x insert(S,x,...) insert x,... in S; return the new set delete(S,x,...) delete x,... from S; return the new set
There's also "!S", that "generates" each element of S, in no predictable order, but the concept of "generators" is too Icon-specific. If it's a matter of borrowing syntax, I would suggest using something like S++, ..., Smember... or like Set::++, ... . Nov 19, 1999
DKF: Membership test should be a boolean operator, and not something with a failure semantics (given correctly typed input.)
AK: The contains command as defined above returns a boolean. Wrappers could be provided to make porting Icon apps easier.
DKF: Hmm. Reading comprehension is obviously not my strong point!
http://web.uvic.ca/~erempel/tcl/sets/sets.html is another Tcl extension that provides set operations.