Overview
| Artifact ID: | 91eace70f43d677cdf9478e2148be122defa7a1e |
|---|---|
| Ticket: | fbc88fb645c5b2f47f16cd0e167ef47de081f212
[variable] doesn't follow variable resolution rules |
| User & Date: | sebres on 2017-06-01 20:54:52 |
Changes
- icomment:
Aaaa... now I've got it. Then more understandable example should be provided: <code><pre> % namespace eval a {variable a "a in [namespace current]"} % catch {namespace delete ::foo}; \ namespace eval foo { set i 0; time { incr i proc test1 {} {catch {set a::a} r; set r} puts -nonewline "${i}.a. direct: "; puts [test1] proc test2 {} {catch {upvar a::a a; set a} r; set r} puts -nonewline "${i}.b. as upvar: "; puts [test2] proc test3 {} {catch {variable a::a; set a} r; set r} puts -nonewline "${i}.c. variable: "; puts [test3] # repeat with existsing ::foo::a if {$i == 1} { puts "Create ::foo::a now ..." namespace eval a {variable a "a in [namespace current]"} } } 2 }; set _ {} 1.a. direct: a in ::a 1.b. as upvar: a in ::a 1.c. variable: can't access "a::a": parent namespace doesn't exist Create ::foo::a now ... 2.a. direct: a in ::foo::a 2.b. as upvar: a in ::foo::a 2.c. variable: a in ::foo::a </pre></code> Why test 1.c. fails? Resp. why resolving of var with "variable" acts differently, <b>if the relative namespace does not exists</b>? Actually it is so documented. It works as designed, just because the completely resolving of var-name by "variable" will be <b>always</b> mapped relative current namespace, thus to the "::foo::a::a" (but ns "::foo::a" not exists, so BOOM). Emphasis to "always" - regardless of whether this variable/namespace exists or not exists. More interesting question would be vice versa - why "upvar a::a a" resolves differently as "variable a::a"? And why it is documented differently... - login: "sebres"
- mimetype: "text/x-fossil-wiki"