Skip to content

Instantly share code, notes, and snippets.

@nat-418
Last active November 14, 2021 08:26
Show Gist options
  • Save nat-418/c9260780168d5dcfd5b622916cec17f1 to your computer and use it in GitHub Desktop.
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 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