Luc <
[email protected]d> wrote:
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.
The message is trying to tell you what it plainly says. You can't do
what you tried to do.
upvar is used to refer to variables in the procedure call stack.
namespaces are not procedures (and do not have a 'position' in the
procedure call stack).
upvar (when used in a procedure) makes a variable in the current
procedure be a reference to another one in the call stack.
upvar used in a namespace is nonsense, as namespaces exist separate
from the call stack. You can't create a "reference" in a namespace to
a local variable in a proc, because while the reference would be valid
while the current proc invocation exists, the moment the proc returns,
the 'reference' in the namespace would be pointing to a variable that
no longer exists (proc locals only exist while the proc is running,
once the proc returns, all of the proc locals go away).
And then this kludge works:
proc do {} {
namespace eval ns {}
set ns::quality "good"
namespace eval ns {
puts $quality
}
}
do
That's not a kluge, that is one valid way to create, and set, a
variable in a namespace.
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.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)