Artifacts Associated With Ticket 959147ffffffffff
Ticket change [36a6d6a787] (rid 107146) by msofer on 2004-05-23 23:28:31:
- assignee initialized to: "msofer"
- cmimetype initialized to: "text/plain"
- comment initialized to:
There is a fundamental problem with varName resolution in namespaces. The variable lookup is as follows: (1) lookup in the current namespace; if the var exists, return a ref (2) lookup in the global namespace; if the var exists, return a ref (3) if the var has to be created, create it in the local namespace Quite apart from the difficulty of defining what it means for a variable to exist (see Bug #959052), this behaviour is surprising and dangerous. A simple variable call may refer to a ns-local or global variable, under circumstances that are difficult to check, and which may vary depending on non-local issues. namespace.n defines the rule as: "Command and variable names are always resolved by looking first in the current namespace, and then in the global namespace. Namespace names, on the other hand, are always resolved by looking in only the current namespace." That the process for variables is black magic is actually implicit in that man page: "You can use the namespace which command to clear up any question about name resolution." But there is no hint of the fragility of the procedure with respect to the existence of the global variable, especially for "creative writing" - ie, creating a variable and setting its value at the same time. Note that commands do not have this creative writing problem: [proc] always creates the command in the current namespace if the name is unqualified. This RFE proposes that we simplify the varName resolution rule in namespaces so that it is always simple and predictable, just as it is for varName resolution in proc bodies. The new description would be: "Command names are always resolved by looking first in the current namespace, and then in the global namespace. Namespace and variable names, on the other hand, are always resolved by looking in only the current namespace."
- foundin initialized to: "None"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "msofer"
- subsystem initialized to: "07. Variables"
- title initialized to: "Restore sanity to variable name resolution"
- type initialized to: "RFE"
Ticket change [28a2cf7e3f] (rid 88733) by msofer on 2006-09-30 00:51:16:
- priority changed to: "8"
Ticket change [5de805bca6] (rid 140083) by msofer on 2014-09-29 00:26:36:
- closer changed to: "nobody"
- comment changed to:
There is a fundamental problem with varName resolution in namespaces. The variable lookup is as follows: (1) lookup in the current namespace; if the var exists, return a ref (2) lookup in the global namespace; if the var exists, return a ref (3) if the var has to be created, create it in the local namespace Quite apart from the difficulty of defining what it means for a variable to exist (see Bug #959052), this behaviour is surprising and dangerous. A simple variable call may refer to a ns-local or global variable, under circumstances that are difficult to check, and which may vary depending on non-local issues. namespace.n defines the rule as: "Command and variable names are always resolved by looking first in the current namespace, and then in the global namespace. Namespace names, on the other hand, are always resolved by looking in only the current namespace." That the process for variables is black magic is actually implicit in that man page: "You can use the namespace which command to clear up any question about name resolution." But there is no hint of the fragility of the procedure with respect to the existence of the global variable, especially for "creative writing" - ie, creating a variable and setting its value at the same time. Note that commands do not have this creative writing problem: [proc] always creates the command in the current namespace if the name is unqualified. This RFE proposes that we simplify the varName resolution rule in namespaces so that it is always simple and predictable, just as it is for varName resolution in proc bodies. The new description would be: "Command names are always resolved by looking first in the current namespace, and then in the global namespace. Namespace and variable names, on the other hand, are always resolved by looking in only the current namespace."
- icomment:
To illustrate the problem, consider: % set a 0 0 % namespace eval x {set a 1; set b 1} 1 % set a 1 % set b can't read "b": no such variable % set x::a can't read "x::a": no such variable % set x::b 1 - login: "msofer"
- mimetype: "text/plain"
- severity changed to: "Minor"
Ticket change [f13002d65b] (rid 140084) by ferrieux on 2014-09-29 07:31:15:
- icomment:
+1 for this RFE, of course, as (unfortunately only a tiny) part of the Augean Stables lying ahead.
- login: "ferrieux"
- mimetype: "text/plain"
- icomment:
Ticket change [fb487ca184] (rid 140113) by aku on 2014-09-29 15:07:13:
- icomment:
IIRC this describes the "creative writing"-problem with var resolution, with the missing namespace var unexpectedly created in the global namespace. Yes, this should be fixed.
- login: "aku"
- mimetype: "text/plain"
- icomment:
Ticket change [91724be600] (rid 148013) by dkf on 2016-07-14 07:11:29:
- assignee changed to: "aku"
- icomment:
This was even hitting <tt>namespace upvar</tt> until recently, but I changed that so that at least that command locates variables without resolvers involved. (That also technically touches the behaviour of <tt>global</tt>, but that was the case where the existing code mostly worked.)
- login: "dkf"
- mimetype: "text/x-fossil-wiki"
Ticket change [c78b20a48d] (rid 261553) by serhiy.storchaka on 2026-11-13 11:18:45:
- closedate changed to: "2461357.9713335303"
- closer changed to: "serhiy.storchaka"
- icomment:
Implemented by TIP 278 in Tcl 9.0: unqualified variable names in a namespace are resolved only in the current namespace, so the example above now sets x::a and leaves ::a alone.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"