Purpose: Definition and discussion of set functionality, especially the function to create a set from a number of elements.
Back to the Chart of proposed set functionality.
Arguments:
Result:
Implementation:
Several variants are possible:
Shortcuts to use in the code:
Timing:
Summary:
Variant A.
proc ::setops::create {args} { if {[llength $args] == 0} { return {} } if {[llength $args] == 1} { return $args } foreach e $args { set aa($e) . } array names aa }
Variant B.
proc ::setops::create {args} { if {[llength $args] == 0} { return {} } if {[llength $args] == 1} { return $args } set args [lsort $args] set last [lindex $args 0] set args [lrange $args 1 end] set res $last foreach e $args { if {[string compare $e $last] != 0} { lappend res $e set last $e } } return $res }
Variant C.
proc ::setops::create {args} { if {[llength $args] == 0} { return {} } foreach e $args { set $e . } info locals }
Variant D
proc ::setops::create {list} { if {[llength $list] == 0} { return {} } foreach $list {.} {break} unset list info locals }
-- AK