Re: Slave interpreters, aliases, and upvar
- From: "MartinLemburg@UGS" <martin.lemburg.ugs@xxxxxxx>
- Date: 13 Apr 2007 02:44:23 -0700
Hello,
I understand what Will wants, I understand Richards and Neils
explainations, but ... I don't understand, why this is planned to be
this way.
If I import a namespace command into another namespace, than this
imported namespace command will be executed inside his original
namespace:
% namespace eval ::foo {
variable foo "this is namespace foo";
proc foo {} {
variable foo;
puts "info level 0 .................= '[info level 0]'";
puts "foo ..........................= '$foo'";
puts "namespace current ............= '[namespace
current]'";
puts "info level -1 ................= '[info level -1]'";
puts "uplevel 1 {namespace current} = '[uplevel 1 [list
namespace current]]'";
}
namespace export -clear foo;
}
% namespace eval ::faa {
variable foo "this is namespace faa";
proc faa {} {
foo;
}
namespace import -force ::foo::*;
}
% ::faa::faa;
info level 0 .................= 'foo'
foo ..........................= 'this is namespace foo'
namespace current ............= '::foo'
info level -1 ................= '::faa::faa'
uplevel 1 {namespace current} = '::faa'
In my opinion, the behaviour Will wants/needs would be comparable.
What're the reasons for this design decision?
Best regards,
Martin Lemburg
UGS - Transforming the Process of Innovation
On Apr 12, 10:03 pm, "w...@xxxxxxxxxxxxxx" <will.duque...@xxxxxxxxx>
wrote:
On Apr 12, 8:13 am, Neil Madden <n...@xxxxxxxxxxxxx> wrote:
I think Will wants a different result -- the variable is in the slave
too. It seems that when the master alias is invoked none of the
callframes from the slave are visible (to upvar, uplevel, or info
level). I don't immediately see the reason why a master cannot see the
stack-frames of the slave that invoked it (these aren't safe interpreters).
To solve Will's immediate problem, I'd guess that you could pass the
interpreter handle as part of the alias and read the variables directly:
proc get {interp varName} {
return [$interp eval [list set $varName]]
}
set interp [interp create]
$interp alias get get $interp
$interp eval {
set a 7
get a
}
Happily, this even works inside procs:
$interp eval {
proc foo {} { set b 9; get b }
foo
}
-- Neil
Neil's exactly right, that's what I'm after. And the answer is,
you can't alias a normal proc that uses upvar or uplevel into
a slave interpreter, and expect it to work across the interpreter
boundary the way it works within a single interpreter. You can
write a command that has the same effect, but it has to be
specially written.
I was hoping there was some magic incantation I hadn't run across.
Oh, well.
Thanks, both.
-- Will
.
- Follow-Ups:
- Re: Slave interpreters, aliases, and upvar
- From: will@xxxxxxxxxxxxxx
- Re: Slave interpreters, aliases, and upvar
- References:
- Slave interpreters, aliases, and upvar
- From: will@xxxxxxxxxxxxxx
- Re: Slave interpreters, aliases, and upvar
- From: suchenwi
- Re: Slave interpreters, aliases, and upvar
- From: Neil Madden
- Re: Slave interpreters, aliases, and upvar
- From: will@xxxxxxxxxxxxxx
- Slave interpreters, aliases, and upvar
- Prev by Date: Re: Tcl_CreateObjTrace - strange command level and order
- Next by Date: Re: performance problem with tcldom2.5 under unix
- Previous by thread: Re: Slave interpreters, aliases, and upvar
- Next by thread: Re: Slave interpreters, aliases, and upvar
- Index(es):
Relevant Pages
|