Artifacts Associated With Ticket 1251123fffffffff
Ticket change [6469b56e58] (rid 92765) by oox on 2005-08-03 15:51:49:
- assignee initialized to: "msofer"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Consider the following: (bin) 1 % namespace eval ::N {set bar 2} 2 (bin) 2 % puts $bar can't read "bar": no such variable (bin) 3 % puts $::N::bar 2 (bin) 4 % set foo 1 1 (bin) 5 % puts $foo 1 (bin) 6 % namespace eval ::N {set foo 2} 2 (bin) 7 % puts $foo 2 (bin) 8 % puts $::N::foo can't read "::N::foo": no such variable I would expect line 6 to create ::N::foo, in the same way that line 1 created ::N::bar, but Tcl notices that ::foo exists, and somehow resolves to it. The NAME RESOLUTION section of the [namespace] manual page says that for unqualified names the following applies: "Command and variable names are always resolved by looking first in the current namespace, and then in the global namespace". This applies 'correctly' to variable *access*, but in a funny way to variable *creation*. What is worse, command creation behaves differently: invoking [proc] with an unqualified procedure name within a namespace creates the procedure in that namespace irrespectively on whether or not an equally named procedure already exists in the global namespace. I understand that modyifing variable resolution rules is something to be avoided. What I propose is adding a sentence to the NAME RESOLUTION section of the [namespace] manual page above describing this observed behaviour. - foundin initialized to: "None"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "oox"
- subsystem initialized to: "21. [namespace]"
- title initialized to: "Variable resolution behaviour and documentation"
- type initialized to: "Bug"
Ticket change [f0863e7616] (rid 109209) by msofer on 2005-08-03 23:20:06:
- icomment:
Logged In: YES user_id=148712 I agree that this behaviour is nasty. It probably will have to remain as it is in the Tcl8 line, and be fixed in Tcl9. The problem is compounded with a surprising definition of "existence" for variables (see bug 959052). The fix is of course to avoid accessing ns variables without "declaring" them first using the [variable] command. This is very frustrating. Do you have a concrete proposal for that explanatory sentence?
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [f5c7adc82b] (rid 130171) by oox on 2005-08-03 23:59:26:
- icomment:
Logged In: YES user_id=662619 I've seen bug 959052: whow! > > Do you have a concrete proposal for > that explanatory sentence? > I knew you were going to ask that one! :-) Given the fact that [variable] "behaves properly", I concede that writing such a sentence is difficult. In fact the current behaviour for variables is consistent with the documentation: if the variable does not exist in the current namespace, Tcl scans the global namespace: if it does exist there, then Tcl resolves to that. The problem, as I see it, is that [proc] behaves differently: % proc x {} {puts "Proc in [namespace current]"} % namespace eval ::N { proc x {} {puts "Proc in [namespace current]"} } That creates both ::x and ::N::x ! May we add something like "(except that [proc] will create a new procedure in a namespace instead of overwiting an equally named procedure in the global namespace)" ? Juan Carlos--- - login: "oox"
- mimetype: "text/plain"
- username: "oox"
- icomment:
Ticket change [a9b2c88ff7] (rid 99190) by dkf on 2005-08-04 00:15:25:
- icomment:
Logged In: YES user_id=79902 Don't mix command and variable resolution. Command resolution is right.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [ca234cee9d] (rid 122410) by msofer on 2006-09-30 08:11:24:
- closedate changed to: "2006-09-30T01:11:24"
- closer changed to: "msofer"
- resolution changed to: "Invalid"
- status changed to: "Closed"