[~] package require XOTcl 0.83 [~] namespace eval Foo {
Class MyClass MyClass instproc init {} { AnotherClass newChild } Class AnotherClass }
AnotherClass [~] Foo::MyClass new invalid command name "AnotherClass" while evaluating {Foo::MyClass new}
Ie. it appears as if methods aren't run in the same namespace as where classes exist (or a child namespace of this). I know this isn't exactly a bug (as I don't think it's specified anywhere?), but I believe the natural behaviour would be for AnotherClass to be found in the example above, as it's specified within the same namespace as Foo.
Is the any chance the current behaviour could be altered to one that I think is more intuitive? Or is there a good reason why not?
- ---------- = = ---------//--+ | / Kristoffer Lawson | www.fishpool.fi|.com +-> | setok@fishpool.com | - - --+------ |-- Fishpool Creations Ltd - / | +-------- = - - - = --------- /~setok/
On Monday 29 January 2001 23:54, Kristoffer Lawson wrote:
[~] package require XOTcl 0.83 [~] namespace eval Foo {
Class MyClass MyClass instproc init {} { AnotherClass newChild } Class AnotherClass }
AnotherClass [~] Foo::MyClass new invalid command name "AnotherClass" while evaluating {Foo::MyClass new}
Ie. it appears as if methods aren't run in the same namespace as where classes exist (or a child namespace of this). I know this isn't exactly a bug (as I don't think it's specified anywhere?), but I believe the natural behaviour would be for AnotherClass to be found in the example above, as it's specified within the same namespace as Foo.
Is the any chance the current behaviour could be altered to one that I think is more intuitive? Or is there a good reason why not?
XOTcl classes actually consist of two namespaces, one for the class object (where procs and class variable are defined) and one for the class features (where the instprocs are defined). The later one is "hidden" in the namespace "XOTclClasses". So during execution of the "init" method the current namespace is:
::XOTclClasses::Foo::MyClass
Usually -- as a user of XOTcl -- you don't have to be aware of that namespace separation. We probably should document it more prominently in the tutorial.
But in the given case its not hard to find out where the AnotherClass command resides, because its in the parent namespace of "MyClass":
namespace eval Foo { Class MyClass MyClass instproc init {} { [[self] info parent]::AnotherClass newChild } Class AnotherClass } Foo::MyClass new
BTW, here, the ::XOTclClasses namespace ain't the problem ... but the Tcl namespace resolution. E.g., we expect:
Object p p proc putHello {} {puts Hello} Object o o proc putHello {} { p putHello } o putHello
to work because Tcl first searches the current Namespace and then the global namespace. This wouldn't functions here either if we surround it with a namespace definition:
namespace eval Foo { Object p p proc putHello {} {puts Hello} Object o o proc putHello {} { p putHello } } Foo::o putHello
But, again info parent works ;)
Regards,
Uwe
On Tue, 30 Jan 2001, Uwe Zdun wrote:
XOTcl classes actually consist of two namespaces, one for the class object (where procs and class variable are defined) and one for the class features (where the instprocs are defined). The later one is "hidden" in the namespace "XOTclClasses". So during execution of the "init" method the current namespace is:
OK, I understand that now and see how it's problematic. However it's still somehow confusing from the developer's point of view that what syntactically appears to be in the same namespace isn't (not your fault, I know :-). I really can't see any way round it, though... ?
In any case, an [info ns] command might be clearer in this case than [info parent] -- even though they give the same result. parent would seem to refer more to the parent object and without an idea of the internal workings one doesn't necessarily know that it is valid in the place of [info ns]. Ie. [info ns] would give the namespace where the object was defined in. Actually this would work for child objects as well. Then the result would differ from [info parent]. Would that make sense?
- ---------- = = ---------//--+ | / Kristoffer Lawson | www.fishpool.fi|.com +-> | setok@fishpool.com | - - --+------ |-- Fishpool Creations Ltd - / | +-------- = - - - = --------- /~setok/