[Xotcl] XOTcl / Tcl Namespace issues
Adam Turoff
adam.turoff at gmail.com
Fri Oct 22 22:20:41 CEST 2004
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
More information about the Xotcl
mailing list