2010.05.31 [JBR] - (is there any convention for dating wiki entries?) I often use tcl [subst] to generate code for my own or one tcl's mini languages. Here is a little template helper that I wrote last week. I like the code because is reuses tcl's foreach and allows substitution of any variables in the current scope, but I'm dissatisfied with the need and technique to awkwardly generate uniq string accumulator variable names to support recursion. Any ideas for improvement would be appreciated. ---- package require Tcl 8.5 proc template:foreach { args } { incr ::template:level set reply [uplevel [subst { set _${::template:level} {} foreach {*}[lrange $args 0 end-1] { append _${::template:level} \[subst {[lindex $args end]}] } set _${::template:level} }]] incr {::template:level} -1 set reply } interp alias {} : {} template:foreach puts [: x { 1 2 3 } { Row $x [: y { a b c } { Column $y }] }] Produces: Row 1 Column a Column b Column c Row 2 Column a Column b Column c Row 3 Column a Column b Column c -------- 2010.05.31 [JBR] - Sitting here watching the A-Team this evening I wrote a similar proc for template:if package require Tcl 8.5 proc K { x y } { set x } proc shift { V } { upvar $V v K [lindex $v 0] [set v [lrange [K $v [unset v]] 1 end]] } proc template:if { args } { set cmd [subst { if { [shift args] } { return \[subst {[shift args]}] } }] while { [llength $args] } { switch [shift args] { else { append cmd [subst { else { return \[subst {[shift args]}] } }] } elseif { append cmd [subst { elseif { [shift args] } { return \[subst {[shift args]}] } }] } } } return [uplevel $cmd] } interp alias {} ? {} template:if set x 1 puts [? $x { True } else { False } ] set x 0 set y 1 puts [? $x { True } elseif { $y } { Y is True!! } else { False } ] Produces: True Y is True!! <>Enter Category Here