No registered users in community xowiki
in last 10 minutes
in last 10 minutes
[Xotcl] XOTcl / Tcl Namespace issues
From: Adam Turoff <adam.turoff_at_gmail.com>
Date: Fri, 22 Oct 2004 16:20:41 -0400
Hi,
Can anyone explain why this program:
package require XOTcl
namespace import xotcl::*
proc ns {} {return "global"}
proc examine {} {puts "[ns] EXAMINE"}
Class Outer
Outer instproc test {} {return [examine]}
namespace eval inner {
proc ns {} {return "inner"}
proc examine {} {puts "[ns] examine"}
Class Inner
Inner instproc test {} {return [examine]}
}
Outer o
o test
inner::Inner i
i test
namespace eval inner {
::o test
::i test
}
produces this output:
global EXAMINE
global EXAMINE
inner examine
inner examine
I've defined the class 'Inner' within the namespace 'inner'. I'd
expect that proc in methods defined within that namespace should first
look within that namespace before looking in the global namespace.
Instead, they look in the namespace currently in use when a method call
is made. (Note how ::o test picks up the definition of inner::examine
when invoked from the inner namespace.)
This is the opposite behavior of how Tcl proc calls work -- when I land
on inner::examine, the [ns] is actually shorthand for inner::ns, not ::ns.
I'm guessing there's a good reason for this behavior, but I can't seem
to find it in the docs.
Thanks,
-- Adam
Date: Fri, 22 Oct 2004 16:20:41 -0400
Hi,
Can anyone explain why this program:
package require XOTcl
namespace import xotcl::*
proc ns {} {return "global"}
proc examine {} {puts "[ns] EXAMINE"}
Class Outer
Outer instproc test {} {return [examine]}
namespace eval inner {
proc ns {} {return "inner"}
proc examine {} {puts "[ns] examine"}
Class Inner
Inner instproc test {} {return [examine]}
}
Outer o
o test
inner::Inner i
i test
namespace eval inner {
::o test
::i test
}
produces this output:
global EXAMINE
global EXAMINE
inner examine
inner examine
I've defined the class 'Inner' within the namespace 'inner'. I'd
expect that proc in methods defined within that namespace should first
look within that namespace before looking in the global namespace.
Instead, they look in the namespace currently in use when a method call
is made. (Note how ::o test picks up the definition of inner::examine
when invoked from the inner namespace.)
This is the opposite behavior of how Tcl proc calls work -- when I land
on inner::examine, the [ns] is actually shorthand for inner::ns, not ::ns.
I'm guessing there's a good reason for this behavior, but I can't seem
to find it in the docs.
Thanks,
-- Adam