Artifacts Associated With Ticket 1587442fffffffff
Ticket change [497900992a] (rid 100056) by msofer on 2006-10-30 20:05:56:
- assignee initialized to: "msofer"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Currently upvar 1 x ::a::y will create a variable y in namespace a, linked to the variable x in the caller's context. This "action at a distance" is undocumented and possibly confusing. It is better IMO to force upvar to only create variables in the current context (namespace or proc call frame). Attached a patch that implements and documents this feature. Note that the tests var-3.7/8 test for the current behaviour.
- foundin initialized to: "None"
- is_private initialized to: "0"
- 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:
let upvar only create variables in the current context
- type initialized to: "RFE"
Ticket change [32a446aa76] (rid 93645) by msofer on 2006-10-31 03:05:56:
- icomment:
File Added - 200677: upvar.patch
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Add attachment "upvar.patch" [b9f4f90668] (rid 129234) by msofer on 2006-10-31 03:05:56.
Ticket change [978a1c9ebf] (rid 110454) by kaitzschu on 2006-11-03 19:10:37:
- icomment:
Logged In: YES user_id=966098 So how does one do (centralized namespace variable templating without copying) set tcnt -1 foreach ns {ns1 ns2 ns3} { for {set cnt 0} {$cnt < 5} {incr cnt} { foreach arn {arr lis dic} { upvar #0 [namespace current]::$arn[incr tcnt] ::${ns}::$arn$cnt } } } after this implementation when ns and cnt are variadic? Instead of upvaring these to heavens high one is supposed to namespace inscope ::$ns upvar [namespace current]::$arn$[incr tcnt] $arn$cnt or something even remotely resembling? Is this "remotely controlled action at distance" then documented (can I trust these links do exist) or am I simply "doing the wrong thing"? - login: "kaitzschu"
- mimetype: "text/plain"
- username: "kaitzschu"
- icomment:
Ticket change [1abb942776] (rid 123032) by msofer on 2006-11-03 22:18:19:
- icomment:
Logged In: YES user_id=148712 The idea is that you [namespace eval] in the namespace where you want your variables to be created; I would code your algorithm as set tcnt -1 foreach ns {ns1 ns2 ns3} { set lst [list namespace upvar [namespace current]] for {set cnt 0} {$cnt < 5} {incr cnt} { foreach arn {arr lis dic} { lappend lst $arn[incr tcnt] $arn$cnt } } namespace eval $ns $lst } On the other hand, your current algorithm I would also code somewhat differently. Note that upvar #0 [namespace current]::x ::a::y is equivalent to the faster (and IMO clearer) upvar 0 x ::a::y So, I would now code yours as set tcnt -1 set lst [list upvar 0] foreach ns {ns1 ns2 ns3} { for {set cnt 0} {$cnt < 5} {incr cnt} { foreach arn {arr lis dic} { lappend lst $arn[incr tcnt] ::${ns}::$arn$cnt } } } eval $lst - login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [691fe4ed30] (rid 103194) by msofer on 2006-11-03 22:22:06:
- icomment:
Logged In: YES user_id=148712 Forgot to mention: [namespace upvar] is in 8.5; it has nothing to do with this feature request really.
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [b1ec952881] (rid 98249) by dgp on 2006-11-04 02:30:50:
- icomment:
Logged In: YES user_id=80530 I haven't had the cycles to spare to check this out rigorously, but it raises my suspicion that it will thoroughly break things done in the Tk script library. Please check that over carefully before proceeding.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment: