[ANN] Multimethod.py -- multimethods for Python

Siggy Brentrup bsb at winnegan.de
Tue Jan 11 13:22:17 EST 2000


Randall Hopper <aa8vb at yahoo.com> writes:

> Randall Hopper:
>  |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)
> 
> To be closer to the truth, I really should have said:
> 
>        if   issubclass( a, Type1 ) and issubclass( b, Type1 ): f_t1_t1(a,b)
>        elif issubclass( a, Type1 ) and issubclass( b, Type2 ): f_t1_t2(a,b)
>        elif issubclass( a, Type1 ) and issubclass( b, Type3 ): f_t1_t3(a,b)
> 
> This alludes to one way multimethods can get into method resolution
> troubles.  If none of the multimethods' parameter signatures match the
> argument types exactly, but multiple multimethods accepting compatible base
> class objects as parameters exist, ...

Can you point us to a formal definition? Seems like you initially got into
trouble explaining it by example :)

>From what I see above it might as well be some dynamic variant of
C++'s template functions.

Thanks
  Siggy

-- 
Siggy Brentrup - bsb at winnegan.de - http://www.winnegan.de/
                  bsb at north.de - http://www.north.de/~bsb/
****** ceterum censeo javascriptum esse restrictam *******




More information about the Python-list mailing list