LEG 20081209:
Are discussed in the page Everything is a list
I want for foreach and while to evaluate to the value of the last executed command.
I want break accept (multiple) arguments just like return (as in Multiple Return Values)
One of the nice things about Tcl is, that lot's of its commands take an arbitrary list of arguments and do something sensible with them. If the return values of commands could also be variadic (see Multiple Return Values), we could stack and stack and stack and ... one command on the other easily.
The following are some salvage ideas for modified Tcl commands.
'What if
Examples for list aware commands:
Variadic versions of typical Tcl commands are implemented with the same name with a '*' at the end.
proc args {} {uplevel set args} proc return* args { set opts {}; set i 0 foreach {o v} $args { switch -exact -- $o { -code - -errorinfo - -errorcode { lappend opts $o $v; incr i 2 } -- {incr i} default {break} } } uplevel return $opts [list [lrange $args $i end]] } proc set* {varName args} { uplevel set $varName $args } proc puts* args { set opts {}; set i 0 set chan stdout foreach {o v} $args { switch -exact -- $o { -chan {set chan $v; incr i 2} -nonewline { lappend opts -nonewline incr i } default {break} } } foreach e [lrange $args $i end] { uplevel puts $opts $chan [list $e] } } proc retThree {} {return* 1 2 3} proc retOne {} {return* {1 2 3}} proc returnOne {} {return {1 2 3}} proc retMany args {return* {*}[args]} puts* "puts* retThree:" {*}[retThree] puts* "puts* retOne:" {*}[retOne] puts* "puts* returnOne:" {*}[returnOne] puts* -nonewline "puts* -nonewline returnOne:\\n\n" {*}[returnOne] \n puts* "puts* retMany a b c d" {*}[retMany a b c d]