Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XOTcl bug ?

9 views
Skip to first unread message

jima

unread,
Aug 18, 2006, 3:59:32 PM8/18/06
to
Hi,

reading XOTcl docs I got the impression one should be able to inherit
from a class that defines its own unknown method and get the
constructors okay just using the magic word "create" that should
override the call to unknown at construction time.

Is this so? I am having trouble with the next example code:

package require XOTcl
namespace import -force ::xotcl::*

Class ::A

::A instproc init {
} {
my instvar MyVar

set MyVar "Hello"
}

::A instproc unknown {
args
} {
my instvar MyVar

puts "$MyVar World... $args"
}

Class ::B -superclass ::A

::B instproc init {
-Msg:required
} {
my instvar MyMsg

set MyMsg $Msg

next

my instvar MyVar

puts "$MyVar World... $MyMsg"
}

::A create a

a yep!

::B create b -Msg wea

b yep!

GN

unread,
Aug 18, 2006, 8:06:35 PM8/18/06
to
jima schrieb:

> Hi,
>
> reading XOTcl docs I got the impression one should be able to inherit
> from a class that defines its own unknown method and get the
> constructors okay just using the magic word "create" that should
> override the call to unknown at construction time.

I don't see the connection between the first and second part of the
sentence. Objects are created always via "create". The method "unknown"
is an ordinary method inherited like all other methods

> Is this so? I am having trouble with the next example code:

If you create an object with some arguments like

"Class create C; C instproc foo {} {;}; C create c -foo"

then after the allocation of the object the method "foo" is called on
the freshly created object (this happens before "init" is called).

In your example, "B create b -Msg wea", object "b" is allocated and
then the method "Msg" is called on this object (before init). Since no
such method is defined in A, B and ::xotcl::Object, the method
"unknown" is called.

Most likely you want something like the following:

Class ::A
::A instproc init {} {

my set MyVar "Hello"


}
::A instproc unknown {args} {
my instvar MyVar

puts "unknown $MyVar World... $args"
}

Class ::B -superclass ::A -parameter Msg
::B instproc init {} {
my instvar Msg MyVar
next
}

So the moral: don' use non-positional arguments for init. In order to
figure out the exact calling sequence, you can use an instfilter like:

Object instproc debug args {
puts "called [self]->[self calledproc]"
set r [next]
puts " [self]->[self calledproc] returns '$r'"
return $r
}
Object instfilter debug


::B create b -Msg wea

Hope this helps!

jima

unread,
Aug 19, 2006, 6:49:30 AM8/19/06
to
It helps a lot...I see the point of the moral

"don' use non-positional arguments for init"

therefore should I drop the idea of using the nice :required thing of
non-positional arguments for init?

How could I enforce that at initial time user should pass a value for a
given argument?

A precondition?
A call to another method _init (from init) that requires that argument?

GN

unread,
Aug 19, 2006, 11:58:50 AM8/19/06
to
jima:

> therefore should I drop the idea of using the nice :required thing of
> non-positional arguments for init?
>
> How could I enforce that at initial time user should pass a value for a
> given argument?
>
> A precondition?
> A call to another method _init (from init) that requires that argument?

One can certainly provide factory methods with required positional or
nonpositional arguments that call create.

There are many ways of testing wether a value was provided: a
precondtion, if you want to force the value to be set by parameters
(the question is, why you want to enforce a certain way of doing so),
an "if" within "init", a postcondtion after "init" to mention a few.

Note, that there are as well many ways to provide the values for
parameters (e.g. subclassing, instmixins), none of these scale well
with nonpositional arguments during object creation.

The other question is, what your "users" are: for end-users, you will
have to test much more and to use a gui testing the input.

jima

unread,
Aug 19, 2006, 1:13:51 PM8/19/06
to
Thanks for your illustrative reply. The factory idea I think is the
most adequate for the issue being discussed.

I am just exploring XOTcl and trying to fix a way of doing things (like
"use nonpositional argument :required").

jima

0 new messages