python hack of the day -- "listable" functions

Tim Peters tim_one at email.msn.com
Sat May 15 03:50:53 EDT 1999


[William Tanksley]
> ...
> Ouch.  Has anyone done work on how to do that?  It's polymorphism, but
> with the action depending on every parameter rather than just one.

So-called multimethods are at the core of the Cecil language, which did a
great deal of advanced work in optimizing their implementation.  Cecil took
this *very* seriously, even to the point of breaking all connection between
class code and source files (if a method dispatches on several objects,
there's no good place to write it -- therefore code organization by file no
longer makes sense).

CLOS (Lisp) does a similar thing via a generalization of generic functions,
but the dispatch rules in Cecil are better thought-out (primarily by
refusing to break ties arbitrarily).

Several years ago there was a longish thread about this in c.l.py.  You can
fake it in Python via creating a registration scheme for multiarg functions,
and IIRC I even posted useless implementation code for that.

at-least-in-the-abstract-it's-a-very-natural-outgrowth-of-oo-ly y'rs  - tim






More information about the Python-list mailing list