PEP 318

Ville Vainio ville at spammers.com
Tue Mar 23 11:36:39 EST 2004


>>>>> "Skip" == Skip Montanaro <skip at pobox.com> writes:

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

    Michele> etc.

    Michele> Way cool, actually :)

    Skip> Okay, but can you explain the mechanism or point me to the
    Skip> original post?  I can't find it on Google (probably too
    Skip> recent).  Multimethod(a,b)() won't

Too recent, or it's because my name is Vainio, not Vanio :-).

    Skip> know that each call is for __mul__ will it (maybe it will
    Skip> peek at the func_name attribute)?  From what you posted, all
    Skip> I saw was multiple definitions of __mul__.  Only the last
    Skip> one will be present as a method in the class's definition.

My post didn't offer anything beyond what Michele suggested. I didn't
present any clear mechanism to do the trick, but I figured it ought to
be possible via func_name attribute, as you suggest. Every declaration
would inject a mapping to some global data structure, and the actual
function call would look it up somehow.

Perhaps the actual callable should be bound to the name by doing

f = make_multimethod("f")

after doing all the declarations. Sadly this limits the usability by
preventing declaration of new variations after the final binding.

Obviously the wrapper function could always return the multimethod
dispatcher for that function name to force the resulting binding to be
the dispatcher at all times.

OTOH, I might be misunderstanding something.

-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list