Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!europa.eng.gtefsd.com!news.umbc.edu!haven.umd.edu!ames!cnn.nas.nasa.gov!hultquis
From: hultquis@nas.nasa.gov (Jeff P. M. Hultquist)
Subject: a cute hack -- delegation after doesNotUnderstand 
Message-ID: <HULTQUIS.94Sep15140936@wk206.nas.nasa.gov>
Sender: news@cnn.nas.nasa.gov (News Administrator)
Nntp-Posting-Host: wk206.nas.nasa.gov
Reply-To: hultquis@nas.nasa.gov
Organization: NASA/Ames Research Center
Date: Thu, 15 Sep 1994 21:09:33 GMT
Lines: 42


A friend (Eric Raible, raible@nas.nasa.gov) and I have
written a Smalltalk-like object system under Scheme -- it
has single-inheritance, and lookup of methods using the
message and the class of the receiver.  And if the
recipient has no acceptable method, then the receiver is
then sent the message doesNotUnderstand.  The method for
doesNotUnderstand (defined in the class Object) simply
calls the debugger.  So far, so good, and Just Like
Smalltalk.

We recently changed the method for doesNotUnderstand so
that, before calling the debugger, it first checks if the
receiving instance can provide us with one or more
"delegate instances" which should receive the original
method in its place.  If a delegate *is* provided, the
system sends the original message to that object and the
execution continues unimpeded.

This has proven to be extremely helpful, and has
eliminated many of the occasions in which we would
otherwise have wanted multiple-inheritance.  For example,
if we have a SET instance, we might choose to forward any
unsupported messages to all of the elements within that
set.  Thus, a set of WINDOW instances can be redrawn by
sending the "redraw" message to the set itself.  The
message-lookup fails and triggers the sending of the
"doesNotUnderstand" message to the set.  That method now
sends the message "delegate" to the same set, receives the
list of delegate instances, and then sends the original
message "redraw" to all of these instances.

Anyway, I think that this is a very cute and useful (and
original?) hack, and that why I am posting it.  -- So that
others might benefit from this idea, and perhaps so that
someone might inform *me* of prior use of this technique
or related uses of the doesNotUnderstand method.


--
Jeff Hultquist                         hultquis@nas.nasa.gov
NASA - Ames Research Center                   (415) 604-4970
