[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multiple polymorphism / multi-methods

>  I would sure like to have method lookup within the language, but how would
>  it work? If you have a system-wide findMethod:for:args: method which you can
>  change then the whole system must work one way or another :-(. If an object
>  could have its own findMethod it would be better, but it could not inherit it
>  from another object unless you accept the default inheritance method for
>  getting to findMethod ( then there would be two inheritance graphs for each
>  object: the normal one for findMethod and a custom one for all other methods ).

A couple of people have asked me about this already, so I'll just
forward the reply I sent them:
Let me explain the scheme I intend for MUST; I think it can be
generalised to work in Self, but I confess I haven't thought it

In MUST, we still have classes (pass'e, I know :-).  Every object must
be an instance of a class.  In implementation terms, this means the
first slot in the object is used to locate the class to find a method
when a message is sent.  Message lookup is a function of class and
selector, and the caching scheme uses these as keys to the method
cache.  So, if a message is sent repeatedly to an instance of the same
class (the usual case), the cache hits after the first lookup, and all
is as fast as usual.

When the cache misses (either the first time, or if there is a
collision), a message findMethod: is sent to the class, with the
selector as argument.  The class is responsible for locating a
suitable method, by whatever method it chooses, and returning it for

The process is recursive when sending findMethod: to the class: the
cache is accessed with the keys (findMethod:, metaclass), and if it
hits, all well and good.  If it misses, the process repeats, sending
findMethod: to the metaclass, etc.  The only thing you have to
ensure is that a findMethod: is eventually found in the cache.  For
Smalltalk-like class and metaclass structures, this means either
Metaclass>findMethod: or Metaclass class>findMethod: must be in the
cache (the search will always get to one of these).

If we substitute words like "behavior" or "trait" for "class" then it
looks like it might be OK for Self.  I'm not sure what the caching
schemes for Self look like, and whether their properties are
significantly different from Smalltalk method caches.  There might be
some detail that needs working out, but I have a hunch there are no
fundamental problems.

Mario Wolczko

More recent thoughts: maybe this won't work out with Self after all.
In Smalltalk and MUST the "class" slot can be used for
meta-descriptions (eg, class methods), but this doesn't transfer to
Self.  I'm not sufficiently familiar with Self to know ... perhaps the
reflective facilities (mirrors?) can be used for this purpose?

   ______      Dept. of Computer Science   Internet:      mario@cs.man.ac.uk
 /~      ~\    The University              uucp:      mcsun!ukc!man.cs!mario
(    __    )   Manchester M13 9PL          JANET:         mario@uk.ac.man.cs
 `-':  :`-'    U.K.                        Tel: +44-61-275 6146  (FAX: 6280)
____;  ;_____________the mushroom project___________________________________