Actually I have three questions regarding "Method Chaining", "next"
and "my variable".
Method Chaining:
In the TIP #257 [http://www.tcl.tk/cgi-bin/tct/tip/257.html] you find
information about the so called "Method-Chaining", and I played a
little bit with that feature and determine, that there is no statement
to when the forward-declaration is called.
In the following example I see that the filters and mixings intercept
before the forward proc. I that well defined behavior?
example:
package require TclOO
oo::class create mixinbase {
constructor {} {
puts "mixinbase::constructor"
}
method foo {} {
puts "mixinbase::foo"
next
}
}
oo::class create mixinderived {
constructor {} {
puts "mixinderived::constructor"
}
method foo {} {
puts "mixinderived::foo"
next
}
}
oo::class create base {
constructor {} {
puts "base::constructor"
}
method foo {} {
puts "base::foo"
}
method filter {} {
puts "base::filter"
next
}
filter filter
mixin mixinbase
forward foo testperclass; #output 1
}
oo::class create derived {
constructor {} {
puts "derived::constructor"
}
method foo {} {
puts "derived::foo"
next
}
method filter {} {
puts "derived::filter"
next
}
filter filter
mixin mixinderived
#forward foo testperclass; #output 2
}
proc testperclass {args} {
puts "proc testperclass"
}
proc testperobject {args} {
puts "proc testperobject"
}
oo::define derived superclass base
set o [derived new]
$o foo
oo::define $o forward foo testperobject
$o foo
output 1:
derived::constructor
derived::filter
base::filter
mixinderived::foo
mixinbase::foo
derived::foo
proc testperclass
derived::filter
base::filter
mixinderived::foo
mixinbase::foo
proc testperobject
Okay, derived::foo is called and "forward by base" evaluating the
next.
output 2:
derived::constructor
derived::filter
base::filter
mixinderived::foo
mixinbase::foo
proc testperclass
derived::filter
base::filter
mixinderived::foo
mixinbase::foo
proc testperobject
Is there any reason why the mixings intercept before forward?
I was just wondering and some dicussion on TclOO would be interesting
too.
next:
Shouldn't ''next'' on derived throw an error?
package require TclOO
oo::class create base {
constructor {} {
puts "base::constructor"
}
method foo {} {
puts "base::foo"
}
}
oo::class create derived {
constructor {} {
next
puts "derived::constructor"
}
method foo {} {
next
puts "derived::foo"
}
}
# oo::define derived superclass base
set o [derived new]
$o foo
output (no error without defined superclass):
derived::constructor
derived::foo
TIP #257 says:
"It is an error to invoke the next
command when there is no superclass
definition of the current method."
constructor->next is no error because oo::class has one
but oo::class has no foo
FYI (with superclass):
oo::define derived superclass base
set o [derived new]
$o foo
output:
base::constructor
derived::constructor
base::foo
derived::foo
my variable:
What's the difference between ''variable'' and ''my variable''?
package require TclOO
oo::class create test {
constructor {} {
my variable myvar
set myvar 1
variable var 2
}
method foo {} {
puts [my varname myvar]
puts [my varname var]
}
method bar {} {
variable myvar
variable var
puts $myvar
puts $var
}
}
set t [test new]
$t foo
$t bar
puts [info object vars $t]
gives:
::oo::Obj4::myvar
::oo::Obj4::var
1
2
var myvar
What is the benefit using ''my variable''?
In the first place, everything looks similar to ''variable''.
Yes. The documentation for the extension should be definitive for this.
The TIP might be a bit inaccurate or out-of-date (I've not been actively
keeping it in synch).
> Is there any reason why the mixings intercept before forward?
> I was just wondering and some dicussion on TclOO would be interesting
> too.
Yes. Forwards are just a different type of method, whereas mixins are a
different type of inheritance. :-)
> Shouldn't ''next'' on derived throw an error?
[...]
> TIP #257 says:
> "It is an error to invoke the next
> command when there is no superclass
> definition of the current method."
That has been changed. Turns out to be a bad idea when the inheritance
graph gets non-trivial (deciding if you have a superclass implementation
at the class level is not as easy as it sounds!) and is one of the
reasons why I now accept that pushing for TclOO in 8.5 was a not-so-good
idea. By finding these things out, life will be better in the future. :-)
> What's the difference between ''variable'' and ''my variable''?
[...]
> What is the benefit using ''my variable''?
> In the first place, everything looks similar to ''variable''.
Apart from the fact that [variable] sucks for more than one variable,
nothing really. Need to re-evaluate that part. :-)
Donal.