4 ms·
tl;dr Tcl has an "uplevel" command that lets you execute code in the variable scope level of the procedure that called it. The classic example is a "do" loop,
by blacksqr 7y ago
tl;dr Tcl has an "uplevel" command that lets you execute code in the variable scope level of the procedure that called it. The classic example is a "do" loop, which Tcl doesn't include out of the box:
proc do {body condition} {
while 1 {
uplevel $body
if {![uplevel [list expr $condition]]} break
}
}
set i 10
do {puts $i ; incr i -1} {$i > 0}
output:
10
9
8
7
6
5
4
3
2
1