Version 1 of Set Functions

Updated 2003-07-03 09:50:55

Mathematical set based functions

Of obvious enough kind, but important, and underused, I guess. Page started by Theo Verelst

These are the first definitions:

 proc setempty {} {return {}}
 proc setadd {a b} {return [setjoin $a $b]}
 proc setisempty {s} { if {$s == {}} {return 1} {return 0} }
 proc setsize {s} {return [llength $s]}
 proc setjoin {a b} {
    set o {};
    foreach i $a {
       if {[lsearch $b $i] < 0} {lappend o $i}
    }; set o [concat $o $b]; return $o
 proc setunion {a b} {set o {}; 
    foreach i $a {if {[lsearch $b $i] >= 0} {lappend o $i}}; return $o}