Method-dispatch
Stig Erik Sandoe
stig@ii.uib.no
Fri, 3 Dec 1999 13:13:14 +0100 (MET)
hi,
[I mail this to the TUNES-list as it may be of interest for other
people interested in languages]
here the other day I was in the need of a mechanism which can be
illustrated as:
(defclass a () ())
(defclass b () ())
(defclass c () ())
(defgeneric foo (obj))
(deftype a-or-b () '(or a b))
(defmethod foo ((obj a-or-b))
(format t "A or B~%"))
(defmethod foo ((obj c))
(format t "C~%"))
(foo (make-instance 'a))
(foo (make-instance 'b))
(foo (make-instance 'c))
which would print:
A or B
A or B
C
--
I solved the specific problem with a macro and the savings in code
are pretty good. The solution just solves my problem however and a
more complete implementation would be interesting. However the
example does imho show that more powerful mechanisms are needed when
doing dispatch (and esp in languages with multi-dispatch).
Currently, all languages I know is based on specialising on
individual types/classes and not sets. Being able to specify various
type-sets to dispatch on would probably allow an even more
expressive language and that is a Good Thing (tm).
I hope this is not a new idea, and that some languages have
implemented such a feature. I am not quite sure on how powerful it
is, but it seems to me as interesting when observing a system as
well and might be of interest in a reflective system or an adaptive
system.
------------------------------------------------------------------
Stig Erik Sandoe stig@ii.uib.no http://www.ii.uib.no/~stig/