Posted to tcl by aspect at Thu May 11 10:52:11 GMT 2017view raw

  1. # nested foreach.
  2. proc foreach* {args} {
  3. set script [lindex $args end]
  4. set args [lrange $args 0 end-1]
  5. foreach {b a} [lreverse $args] {
  6. set script [list foreach $a $b $script]
  7. }
  8. tailcall {*}$script
  9. }
  10. foreach* {*}{
  11. compartment {5compt}
  12. generator {one two three}
  13. switchboard {on two three}
  14. } {
  15. puts [list compartment $compartment generator $generator switchboard $switchboard]
  16. }
  17.