This is not necessarily the current version of this TIP.
|Title:||Specify and Unify Variable Linking Commands|
|Version:||$Revision: 1.3 $|
|Author:||Miguel Sofer <msofer at users dot sourceforge dot net>|
|Created:||Sunday, 01 October 2006|
|Keywords:||Tcl, global, variable, upvar, namespace upvar|
The purpose of this TIP is to simplify and clarify the semantics of the commands in Tcl that couple variables in different scopes together.
This TIP proposes to specify and document the behaviour of the different variable linking commands in Tcl: global, variable, upvar and namespace upvar.
In particular, as many of these commands were initially designed to be mainly useful from within procedure bodies, the documentation does not specify their behaviour with respect to qualified variable names.
This TIP proposes to specify and document this behaviour, insuring that it is essentially the same in all these commands.
There have been a few bug reports concerning the behaviour of variable linking commands with respect to qualified variable names: 604226, 1274916, 1274918. Some are real bugs, some are just surprising but correct behaviour, some are surprising unspecified behaviour.
Within proc bodies all of these commands create local variables that are linked to original variables elsewhere (the following assumes that local is a non-qualified name):
"global var" creates a local variable "[namespace tail var]" that is linked to "var" as resolved from the global namespace.
"variable var" creates a local variable "[namespace tail var]" that is linked to "var" as resolved from [namespace current].
"upvar level var local" creates a local variable "local" that is linked to "var" as resolved in the context of the frame identified by level. It is an error to try to link to a proc-local variable from a namespace context.