Posted to tcl by aspect at Thu May 11 11:01:59 GMT 2017view raw
- # nested foreach.
- proc foreach* {args} {
- set script [lindex $args end]
- set args [lrange $args 0 end-1]
- set dictval [concat {*}[lmap {k _} $args {string cat "[list $k] \[set [list $k]\]"}]]
- set script "set values \[dict create $dictval\]\n $script"
- foreach {b a} [lreverse $args] {
- set script [list foreach $a $b $script]
- }
- tailcall {*}$script
- }
- foreach* {*}{
- compartment {5compt}
- generator {one two three}
- switchboard {on two three}
- } {
- puts [list PERMUTATION {*}$values]
- }