Multi-Methods
Languages using Multi-Methods:
- CLOS (Common Lisp Object System)
- Cecil
- Kaleidoscope
Is it object-oriented?
CLOS: generic functions (function call, case-analysis style implementation)
Cecil: method is inside each of the arguments it discriminates on
Sample Cecil declarations:
x@smallint + y@smallint
x@smallint + y@bigint
x@bigint + y@smallint
x@bigint + y@bigint
asBigint(X@smallint)
Each of these methods that has a smallint as an argument is "in" the
smallint class.
Possible Problems
- no protection -- can get access to the internals of
an object by defining a method that dispatches on it
- doesn't work well with distributed object-oriented
systems (or at least it's not clear how to make it work well)
Kaleidoscope
Kaleidoscope is a constraint imperative language, which
combines constraints with standard object-oriented programming
In Kaleidoscope, multiple dispatch is essential. Consider a + constraint.
As in other object oriented languages, the meaning of + is determined by
the classes of the arguments (+ means something different for floats and
points).
x+y = z
Suppose y and z are known, and x is unknown. In this case, we should
definitely not dispatch on the class of x to decide what + means!