'''`[namespace] upvar`''', a subcommand of [namespace], makes a [variable] in a [namespace] an alias for another variable. ** Synopsis ** : '''[namespace children]''' ''?namespace? ?pattern?'' : '''namespace upvar''' ''namespace otherVar myVar'' ?''otherVar myVar ...''? : '''[namespace code]''' ''script'' : '''[namespace current]''' : '''[namespace delete]''' ''?namespace namespace ...?'' ** Description ** : '''[namespace ensemble]''' ''option ?arg ...?'' '''`[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%|%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 eval]''' ''namespace arg ?arg ...?'' `namespace upvar' is a convenience command that doesn't add any functionality not previously available with `[upvar]`. The following are equivalent: : '''[namespace exists]''' ''namespace'' 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 ** ====== [namespace]: the primary command for working with namespaces list the commands in a namespace: <> Command | Tcl syntax help