Version 8 of namespace upvar

Updated 2014-08-14 16:06:45 by pooryorick

namespace upvar, a subcommand of namespace, makes a namespace variable an alias for another variable.

Synopsis

namespace upvar namespace otherVar myVar ?otherVar myVar ...?

Description

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:

set ns ::foo
upvar #0 ${ns}::bar boo

and

set ns ::foo
namespace upvar $ns bar boo

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.

See Also

namespace
the primary command for working with namespaces