There isn't much about this on Google.
This doesn't work:
proc do {} {
set adjective "good"
namespace eval ns {
upvar 1 adjective quality
puts $quality
}
}
do
error: bad variable name "quality": can't create namespace variable
that refers to procedure variable
I understand the words but not what the message is trying to tell me.
And then this kludge works:
proc do {} {
namespace eval ns {}
set ns::quality "good"
namespace eval ns {
puts $quality
}
}
do
I feel like I just cheated to do somethinhg I was not supposed to.
What exactly happened here?
You tried to do something that is nonsensical. upvar connects together
local variables in different procs. Namespaces are not procs,
therefore, trying to connect a namespace variable to a proc local is >nonsense.
On Mon, 8 Jan 2024 22:35:17 -0000 (UTC), Rich wrote:
You tried to do something that is nonsensical. upvar connects
together local variables in different procs. Namespaces are not
procs, therefore, trying to connect a namespace variable to a proc
local is nonsense.
Thank you.
Your explanation makes a lot of sense, but can you really blame me for
the mixup when there is a 'namespace upvar' command? Does that command qualify as 'nonsense' too?
No, because it is defined as linking namespace variables into the
current proc as locals for that proc.
On Tue, 9 Jan 2024 01:49:58 -0000 (UTC), Rich wrote:
No, because it is defined as linking namespace variables into the
current proc as locals for that proc.
OK. Though still weird that someone might prefer
namespace upvar ns var localvar
set localvar 125
to a much simpler
set ns::var 125
Anyway, I wish I had used namespaces sooner. I spent so much time
worrying about keeping track of the tabs, like
set tabID [dict get $::FlowControl ActiveTabID]
then using tons of [dict get] here and there to access multiple values
in complicated ways.
Now I just get the ID then run everything inside
namespace eval $tabID {}
and everything just works with much simpler syntax and all the context separation I always meant in the first place. Even that thread thing
is working with simpler code.
Luc <luc@sep.invalid> wrote:
On Tue, 9 Jan 2024 01:49:58 -0000 (UTC), Rich wrote:
No, because it is defined as linking namespace variables into the
current proc as locals for that proc.
OK. Though still weird that someone might prefer
namespace upvar ns var localvar
set localvar 125
to a much simpler
set ns::var 125
Anyway, I wish I had used namespaces sooner. I spent so much time
worrying about keeping track of the tabs, like
set tabID [dict get $::FlowControl ActiveTabID]
then using tons of [dict get] here and there to access multiple values
in complicated ways.
Now I just get the ID then run everything inside
namespace eval $tabID {}
and everything just works with much simpler syntax and all the context
separation I always meant in the first place. Even that thread thing
is working with simpler code.
You've simply created a "poor man's object".
I.e., you've recreated "objects" from the existing primitives, but
without some of the niceties that tcloo provides for objects.
Each tab has a backing 'object' and that 'object' holds all the state
data for the tab (which is one of the benefits of objects, easier
'separation of concerns' like this).
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (3 / 13) |
Uptime: | 03:52:26 |
Calls: | 9,775 |
Calls today: | 16 |
Files: | 13,748 |
Messages: | 6,186,606 |