Single-Dispatch\’s Win

There is a common feature in single-dispatch OO systems that I haven\’t seen in multiple dispatch: handling of \”missing methods\”. In Ruby, it\’s method_missing(); in Perl it\’s AUTOLOAD; Smalltalk, doesNotUnderstand:; and Obj-C, forwardInvocation:. For the C++ and Java programmer, who lack such functionality, I\’ll describe it a bit:

If you define (say, in Ruby) method_missing() on a class, and a user calls a method on that class which does not exist, Ruby will pass the call to your method_missing() implementation and you\’re given the opportunity to handle the call there. This can be useful in a number of cases; one of those is where the user may expect certain things to exist as methods, but the set may be variable or unbounded. For example, creating an XML structure, and allowing the user to just assuming the existance of a method matching each element.

In Lisp (and other multiple-dispatch systems that I\’m aware of) there is no such ability. I\’ve run into a number of places where I\’ve wanted such a mechanism. I don\’t have any solution in mind to this now, but it is something that I would like to think about. And maybe get input from others about.

Comments are closed.