Re: [TCLCORE] Pre-CFV: TIP#257
by Daniel A. Steffen other posts by this author
May 7 2008 1:02PM messages near this date
Re: [TCLCORE] Pre-CFV: TIP#257
|
Re: [TCLCORE] Pre-CFV: TIP#257
Hi Donal,
On 07/05/2008, at 16:57, Donal K. Fellows wrote:
> Daniel A. Steffen wrote:
> > How do I create a metaclass destructor though (without going
> > through the root oo::object destructor as in my example)? wouldn't
> > I need self.destructor? (or maybe I'm getting (meta)confused given
> > the hour ;-)
>
> oo::class create metaclass {
> superclass oo::class
> destructor { ... }
> }
> metaclass create ordinaryclass {
> ...
> }
> ordinaryclass create instance
ah yes, of course, cool, that works nicely, c.f. below.
minor question about API naming consistency that occurred to me while
playing with this:
why is it [oo::define superclass] but [info class superclasses]? both
deal with a list of classes, so why not 'superclasses' in both cases?
> > this appears to be triggered by the fact that L is a subclass of
> > the class to be mixed into (i.e. oo::object).
> > maybe mixing into oo::object needs to be made an exception for the
> > TclOOIsReachable() check in TclOODefineMixinObjCmd()?
>
> Umm, yes. Chalk that one up as a bug. Please file an issue report
> so I remember to fix it. :-)
ok, will do
> > when mixing L into oo:class instead, the mixed-in destructor did
> > not get called at class destruction, is it not possible to mixin
> > destructors?
>
> Not at the moment. Are you arguing that that's a bug? (I can fix it
> if you are... :-))
my intuition would be that constructor/destructor of mixins should be
called, given that mixin methods can access instance variables of the
mixin class, which may need to be setup/torn down. FWIW, that is also
what XOTcl appears to be doing. Will file a bug.
Cheers,
Daniel
--
** Daniel A. Steffen **
** <mailto:das@[...].net> **
#---------------------------------------------------------------
puts "TclOO [package require TclOO]:"
##destruction logging:
oo::define oo::object destructor {puts " [self] destroyed"}
oo::class create M {
superclass oo::class
destructor {
set sups [info class superclasses [self]]
foreach sub [info class subclasses [self]] {
set subsups [info class superclasses $sub]
set i [lsearch -exact $subsups [self]]
oo::define $sub superclass {*}[lreplace $subsups $i $i {*}$sups]
}
foreach inst [info class instances [self]] {
set sup [lindex $sups 0]
oo::define $inst self.class $sup
}
next
}
}
M create A {}
M create B {superclass A}
puts " class B with superclasses [info class superclasses B]"
A create O
puts " object O of class [info object class O]"
puts "destroying A:"
A destroy
puts " class B with superclasses [info class superclasses B]"
puts " object O of class [info object class O]"
puts "destroying B & O:"
B destroy; O destroy
#---------------------------------------------------------------
# TclOO 0.2:
# class B with superclasses ::A
# object O of class ::A
# destroying A:
# ::A destroyed
# class B with superclasses ::oo::object
# object O of class ::oo::object
# destroying B & O:
# ::B destroyed
# ::O destroyed
#---------------------------------------------------------------
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Tcl-Core mailing list
Tcl-Core@[...].net
https://lists.sourceforge.net/lists/listinfo/tcl-core
Thread:
Twylite
Will Duquette
Kevin Kenny
Kevin Kenny
Will Duquette
Arnulf Wiedemann
Will Duquette
Kevin Kenny
Donal K. Fellows
Twylite
Larry W. Virden
Twylite
Gustaf Neumann
Larry McVoy
Gerald W. Lester
Vasiljevic Zoran
Larry McVoy
Gerald W. Lester
Larry McVoy
Tomasz Kosiak
Gustaf Neumann
Donal K. Fellows
Daniel A. Steffen
Donal K. Fellows
Daniel A. Steffen
Donal K. Fellows
Donal K. Fellows
Daniel A. Steffen
Gerald W. Lester
Vasiljevic Zoran
Arnulf Wiedemann
Tom Krehbiel
Vasiljevic Zoran
Donal K. Fellows
Gustaf Neumann
Brian Griffin
Gustaf Neumann
Donal K. Fellows
Gustaf Neumann
Kristoffer Lawson
Daniel A. Steffen
Twylite
Donal K. Fellows
Will Duquette
Donal K. Fellows
Will Duquette
Arnulf Wiedemann
dgp
Donal K. Fellows
Arnulf Wiedemann
Twylite
Will Duquette
Twylite
Donal K. Fellows
Stefan Sobernig
Donal K. Fellows
Stefan Sobernig
|