PEP 318
Andrew Bennetts
andrew-pythonlist at puzzling.org
Wed Mar 24 19:21:19 EST 2004
On Wed, Mar 24, 2004 at 09:44:09AM -0600, Skip Montanaro wrote:
>
> 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.
The first parameter thing is just a result of the confusion between myself
and Ville about whether we were discussing methods or functions... I thought
it was odd too, but I was trying to adapt the examples given earlier in the
thread as faithfully as I could, but I didn't realise Ville was talking
about functions, not methods. Imagine my examples with the first argument
to multimethod removed, i.e.:
class C:
def foo(self, other):
...
foo = multimethod(Matrix)(foo)
def foo(self, other):
...
foo = multimethod(Vector)(foo)
class C2:
def foo(self, other):
...
foo = multimethod(String)(foo)
I still don't get how a implementation of multimethod using a global
dispatch table can support all of these calls correctly:
c, c2 = C(), C2()
c.foo(some_matrix) # This is fine
c.foo(some_vector) # This is fine too
c.foo(some_string) # This should fail!
c2.foo(some_matrix) # This should also fail!
c2.foo(some_string) # This is fine
Well, maybe you can do it by stack introspection in the multimethod call to
determine what class definition you're in, but that's vile.
-Andrew.
More information about the Python-list
mailing list