For an example like this, the simplest effective answer is to use
[tailcall].
package require Tcl 8.6
proc test {} { # As above }
proc instate {statelist args} {
lassign $args trueCode else falseCode
tailcall eval $trueCode
}
% test
a
inside instate call
In the more general case, you'll want to examine how to [catch] and then
re-raise exceptions. See the [return] documentation:
http://www.tcl.tk/man/tcl8.6/TclCmd/return.htm
proc instate {statelist args} {
lassign $args trueCode else falseCode
catch {uplevel 1 $trueCode} m o
dict incr o -level
return -options $o $m
}
Polishing up details in the -errorinfo is left as an optional exercise
(see TIP 90).
--
| Don Porter Applied and Computational Mathematics Division |
|
donald...@nist.gov Information Technology Laboratory |
|
http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|