[ANN] Multimethod.py -- multimethods for Python

Randall Hopper aa8vb at yahoo.com
Tue Jan 11 11:36:56 EST 2000


Doug Hellmann:
 |Tim Peters wrote, in response to Neel Krishnaswami's post on multimethods:
 |> 
 |> Can't say I was surprised -- few people had thought about multimethods
 |> then.  They're better known now, but also much easier to get at via
 |> Dylan now (which people should definitely look into if they like what
 |> they see in your emulation).
 |
 |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.

If you think best in implementation as I do:

   def f( a,b ):
     if   type(a) == Type1 and type(b) == Type1: f_t1_t1(a,b)
     elif type(a) == Type1 and type(b) == Type2: f_t1_t2(a,b)
     elif type(a) == Type1 and type(b) == Type3: f_t1_t3(a,b)
     ...

My impression is that it is the above, without as much mess and maintenance
headache as a codified dispatch table.  

The first paragraph of the Intro in:

    http://www.cs.washington.edu/research/projects/cecil/cecil/www/www/\
    Papers/ecoop99.html

sums it up.

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list