class mixins are in the wrong spot in the callchain
Closed / Fixed1998221fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-06-19 20:27:08
Executing the following script:
oo::class create A {
method a_with_next {} {puts a_awn ; next}
method a {} {puts a_a}
}
oo::class create AM {
method a_with_next {} {puts am_awn ; next }
method a {} {puts am_a ; next}
method b {} {puts a_b ; next}
}
oo::define A mixin AM
A create a
a a
a a_with_next
a b
gives the following output:
a_a
a_awn
am_awn
a_b
e.g. methods in the class are called before the methods in the mixin class.
This has several consequences:
1) If a class should be extensible by a mixin, the method defined in the class should call next to run the functionality in the mixed in method.
2) because you will not know a priori if anyone would extend your class in this way you will have to end every method with a call to next
3) because of 2, next is a silent noop when no next method exists.
If the call chain is changed so that mixed in methods are called first:
1) methods will not need a call to next to be extensible by mixins
2) a next with no next method can become an error again (as it should be IMO)
Also note that this will then be consistent with mixins on objects, where the mixed in method *is* called before the method on the object.
dkfplain2008-06-20 03:41:11
Logged In: YES
user_id=79902
Originator: NO
% namespace path oo
% class create A {method a {} {puts A.a; next}}
::A
% class create AM {method a {} {puts AM.a; next}}
::AM
% define A mixin AM
% A create a
::a
% a a
A.a
AM.a
% class create BM {method b {} {lappend ::result BM; next}}
::BM
% class create B {mixin BM; method b {} {lappend ::result B; next}}
::B
% set ::result {}
% [B new] b
% set result
B BM
% class create CM {method c {} {lappend ::result CM; next}}
::CM
% class create C {method c {} {lappend ::result C; next}}
::C
% C create c
::c
% objdefine c mixin CM
% set ::result {}
% c c
% set result
CM C
dkf Ticket [1998221fff]: 1 change
[History diff]2008-06-20 03:41:39
dkfplain2008-06-20 04:03:42
Logged In: YES user_id=79902 Originator: NO Now fixed in Tcl and TclOO package
Log in (anonymous is fine) to add a comment.