On Tuesday 24 April 2001 20:25, Kristoffer Lawson wrote:
On Tue, 24 Apr 2001, Gustaf Neumann wrote: Personally I've never had the need for it (per-object procs were fine). Usually I'd always want to keep a language as simple as possible. Of course if I had a need for such a structure then maybe I would change my stance, but until it becomes very common I'm probably content with the current system.
well, here is a quite a short and simple solution that might be sufficient for most situations:
==================================================================================== Class InheritClassProc InheritClassProc instproc unknown {m args} { foreach c [[self] info heritage] { if {[info command ${c}::$m] != ""} {return [eval $c $m $args]} } next } Class instmixin InheritClassProc ====================================================================================
one can add a ...if {![.. ismetaclass ...]} to avoid its call on the creation of classes. To test it in the originally posted problem, the following example calls for "B test ..." the proc of A, and creates a new object for "B test".
================================================== Class A A proc test {x y} { expr {$x*$y} } Class B -superclass A puts result=[B test 47 11] puts result=[B test1] ==================================================
If you have a speed sensitive program, or you do not want to globber the space of object names, i would recommend to invoke the create method explizitly like "B create test1", or to create an instance of B named "test", use "B create test"
best regards -gustaf