PEP 318

Skip Montanaro skip at pobox.com
Tue Mar 23 16:46:31 CET 2004


    Michele> And don't forget Ville Vanio's idea of using the new syntax to
    Michele> implement multimethods:

    Michele> def __mul__(self,other) as multimethod(Matrix,Matrix):
    Michele>     ...

    Michele> def __mul__(self,other) as multimethod(Matrix,Vector):
    Michele>    ...

    Michele> def __mul__(self,other) as multimethod(Matrix,Scalar):
    Michele>   ...

    Michele> def __mul__(self,other) as multimethod(Vector,Vector):
    Michele>   ...

    Michele> def __mul__(self,other) as multimethod(Vector,Scalar):
    Michele>   ...

    Michele> etc.

    Michele> Way cool, actually :)

Okay, but can you explain the mechanism or point me to the original post?  I
can't find it on Google (probably too recent).  Multimethod(a,b)() won't
know that each call is for __mul__ will it (maybe it will peek at the
func_name attribute)?  From what you posted, all I saw was multiple
definitions of __mul__.  Only the last one will be present as a method in
the class's definition.

Skip




More information about the Python-list mailing list