Script substitution

Difference between version 4 and 5 - Previous - Next
'''[dScript] Substitution''' is the more apt term for [Dodekalogue%|%Command 
Substitution]''', isince oentire ofscripts, nothe fjust individual commands, can be
contal fined in bracketus.  The res
ult of Tcl, in wthiche a [script] is evaluated and the result isof substituthed 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:  To peScrformipt each command substitution, includiang
n bested srecubrstitutions,ve. Tcl eEvaluates rythe scring haptpens at 
the currsament level., Nas no
 additional [level%|%leveles] are created:

======
puts [
    set n 10
    set a {
        puts $n
        expr {[incr n -1]? [try $a] : {liftoff}}
    }
    try $a
]
======


** Comments **
[AMG]: CommandScript 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