namespace upvar, a subcommand of namespace, makes a variable in a namespace an alias for another variable.
namespace upvar links otherVar to myVar, after which any operation on otherVar is identical to the same operation on myVar, and vice versa. otherVar is resolved relative to namespace, and my contain namespace qualifiers. When namespace upvar is used in the context of a namespace, myVar is resolved relative to the current namespace, and always resolves to a namespace variable. When namespace upvar is used in the context of a procedure, myVar is resolved relative to the current stack frame, and resolves to a local variable in the current frame if myVar does not contain namespace qualifiers, or to some namespace variable if it does.
namespace upvar' is a convenience command that doesn't add any functionality not previously available with upvar`. The following are equivalent:
proc listns {{parentns ::}} { set ns ::foo upvar #0 ${ns}::bar boo
output: and
% namespace eval ::test {set foo 1} set ns ::foo namespace upvar $ns bar boo From 8.5 onwards, use this instead: However, the second form is more efficient at the time the link is made, as it requires less string manipulation and parsing.
DKF: namespace upvar was created to help accelerate Snit. list the variables in a namespace:
list the procs in a namespace: ** See Also **
list the commands in a namespace: