[ANN] Multimethod.py -- multimethods for Python

Doug Hellmann doughellmann at home.com
Tue Jan 11 12:24:03 EST 2000


How is this different from function overloading, as implemented in C++? 
I'm not a C++  user, but my impression is the effect would be the same. 
Is that the point?

Doug

Randall Hopper wrote:
> 
> 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, ...
> 
> --
> Randall Hopper
> aa8vb at yahoo.com




More information about the Python-list mailing list