[ANN] Multimethod.py -- multimethods for Python

Tres Seaver tseaver at aftershock.neosoft.com
Tue Jan 11 18:18:16 EST 2000


In article <85fnbk$j6h$1 at nntp9.atl.mindspring.net>,
Aahz Maruch <aahz at netcom.com> wrote:
>In article <20000111113656.A42270 at vislab.epa.gov>,
>Randall Hopper  <aa8vb at yahoo.com> wrote:
>>Doug Hellmann:
>> |
>> |Could one of you post a brief description of what a multimethod is, or
>> |maybe just a pointer to a definition somewhere?
>>
>>I had the same question yesterday and did a little surfing.  Basically,
>>instead of switching off just the type of 'self' to determine which method
>>to call, you switch off the type of other arguments as well.
>
>IOW, similar to C++-style multiple dispatch?

Not quite, I think -- C++ uses overloading and/or templates to achieve static
(compile-time) selection of a function; Lisps's multi-methods are virtual
(dispatched at runtime), but selected the types of all the arguments, not
just of this->. (In fact, in Lisp, methods aren't declared within classes
at all!)

Only matters if you are inheriting, but it makes something like the Visitor
pattern practically unnecessary.

As an example (stealing from Scott Meyer's C++ World talk on double dispatch),
think of a game where players, NPC's, ships, and other objects are careening
about in zero-gee;  the effect of a collision between two of them depends on
all their types, and not merely the first one the game engine picks up.
-- 
---------------------------------------------------------------
Tres Seaver           tseaver at palladion.com       713-523-6582
Palladion Software    http://www.palladion.com



More information about the Python-list mailing list