Last active
November 14, 2021 08:26
-
-
Save nat-418/c9260780168d5dcfd5b622916cec17f1 to your computer and use it in GitHub Desktop.
Using Tcl's uplevel command to create a static variable control structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an example of using Tcl's uplevel to create new control structures, | |
# and can be found on page 59 of "Exploring Expect" by Don Libes. | |
# Like variables declared global, variables declared static are | |
# accessible from other procedures. However, the same static variable | |
# cannot be accessed by procedures in different files. | |
# | |
# @param args The aguments to static are the same as global. | |
# @return Void, the side effect is manipulating the static state array. | |
proc static {args} { | |
set unique [info script] | |
foreach var $args { | |
uplevel 1 "upvar #0 static($unique:$var) $var" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment