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

tcl oo superclass does not get created when there is no "next" statement in the constructor

93 views
Skip to first unread message

tombert

unread,
Apr 16, 2013, 11:15:57 AM4/16/13
to
Considering this example here:

oo::class create B {
variable bvar
constructor args {set bvar "fromB"}
method getBvar args {return $bvar}
}

oo::class create A {
superclass B
variable avar
constructor args {set avar "fromA"}
method getAvar args {return $avar}
}

Without putting the "next" statement into the constructor of A it is impossible to call methods from class B:

> set a [A new]
::oo::Obj92
> $a getAvar
fromA
> $a getBvar
invalid command name "getBvar"

The help says: "Within the constructor, the next command should be used ..."
Either the help should say "... must be used ..." or this is a bug.

thx

Donal K. Fellows

unread,
Apr 17, 2013, 8:21:10 AM4/17/13
to
On 16/04/2013 16:15, tombert wrote:
> The help says: "Within the constructor, the next command should be used ..."
> Either the help should say "... must be used ..." or this is a bug.

I've come across (rare!) cases where preventing the parent constructor
from running is desired. There are also cases for using [nextto] instead
of [next] (e.g., control over diamond inheritance).

Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.

tombert

unread,
Apr 22, 2013, 5:11:48 AM4/22/13
to
Ok - so it is better to leave it to "... should be used ...".

But why can I not access the method from class B? Should it not be automatically exported independently of the "next" statement?

thx

gustafn

unread,
Apr 22, 2013, 1:04:15 PM4/22/13
to
I have not potential explanation for this. I think, this is a bug.

tombert

unread,
Apr 23, 2013, 5:31:02 AM4/23/13
to

pal...@yahoo.com

unread,
Apr 23, 2013, 9:50:56 AM4/23/13
to
What Tcl and TclOO version are you using ? From 8.6 I get

(wits) 51 % set a [A new]
::oo::Obj63
(wits) 52 % $a getAvar
fromA
(wits) 53 % $a getBvar
can't read "bvar": no such variable

which is what I would expect given that B's constructor was not called.

/Ashok


On Tuesday, April 16, 2013 8:45:57 PM UTC+5:30, tombert wrote:
> Considering this example here:
..
0 new messages