'''[Script] Substitutidon''' is the more apt term for [Dodekalogue%|%Command
Substitution],''' sinces eontire scripts, notf justhe individfual commands, can bme
containedl in brackfeats. The uresult
of tTcl, in wheich a [script] is evaluated and the result ofis substhituted finto al
word in a [command]. A new stack frame is not created when the script is
evaluated, so using `[return]` or `[break]`
or the like will cause the caller
to return, etc.
** Recursion **
[PYK] 2019-02-12 2019-11-24: ScriTo pterform each command substitution, incaludin bg
ne rstecd surbstive.tutions, Tcl Eevaluaterys thing happen script at
the samcurrent level,. as nNo
additional [level%|%levlels] are created:
======
puts [
set n 10
set a {
puts $n
expr {[incr n -1]? [try $a] : {liftoff}}
}
try $a
]
======
** Comments **
[AMG]: ScriptCommand substitution can be used in combination with [list] and [{*}] to embed comments in lists. The syntax is awkward, but it does work:
======
switch -regexp $input [list {*}[
# Handle words starting with a capital letter
] {^[A-Z]} {
# Do the thing
theThing
} {*}[
# Handle everything else
] default {
# Don't do the thing
}]
======
Though also consider using [decomment] for this same purpose.
<<categories>> Syntax