PEP 318

Skip Montanaro skip at pobox.com
Wed Mar 24 10:44:09 EST 2004


    Andrew> So, your proposal would work equally well (functionally, anyway,
    Andrew> just not look as nice) like this:

    Andrew> class C:
    Andrew>     def foo(self, other):
    Andrew>         ...
    Andrew>     foo = multimethod(Matrix, Matrix)(foo)

    Andrew>     def foo(self, other):
    Andrew>         ...
    Andrew>     foo = multimethod(Matrix, Vector)(foo)

    Andrew> Which is to say, I don't understand how that can work -- the
    Andrew> first definition of foo gets clobbered.

    Andrew> You *could* have a global registry that's keyed off func_name,
    Andrew> as you suggest, but that doesn't work in general... what if I
    Andrew> later have:

    Andrew> class C2:
    Andrew>     def foo(self, other):
    Andrew>         ...
    Andrew>     foo = multimethod(Long, String)(foo)

    Andrew> How is the registry not going to help distinguish between the
    Andrew> foo methods from C, and the foo methods from C2?

By keying the dispatch table on (foo, Matrix) or (foo, Long).  Note that
your classes (C and C2) make no sense given that the first parameter to the
multimethod() calls are Matrix and Long, respectively.

Skip




More information about the Python-list mailing list