Multiple dispatch again

Samuele Pedroni pedronis at bluewin.ch
Fri Jan 3 12:44:36 EST 2003


> |I think a multi-argument generalization of super (similar also to Cecil
> |resend), would be the most flexible, pythonic solution.
>
> My first feeling on reading Pedroni's suggestion was that I should
> really implement this. But as I reflect on it, I have trouble seeing an
> actual benefit.
>
> It seems to me that when you want to propogate dispatch to a generic
> "less specific" method, you would -always- want to do so either at the
> start or end of the current methods code body.
>
> Now I can easily imaging that a method body would want to call on some
> -specific- function that happened to be one of the multimethods.  But
> AFAICS, it wouldn't be simply "some more general method".  Especially
> given that no more general method might be defined at all, and the call
> would have to be guarded by a try/except in case nothing existed.
>
> E.g.
>
>     def very_general(...): ...
>     def slightly_general(...): ...
>     def pretty_specific(...):
>         ...do stuff
>         val1 = very_general(...)   # this make sense!
>         val2 = next_method(...)    # what will this be??!
>         ...do more stuff...
>
>     multi.add_rule((Thing,), very_general)
>     multi.add_rule((Foo,), slightly_general)
>     multi.add_rule((MyOwnFoo,), pretty_specific)
>
>     multi(myownfoo)
>
> Depending only on which rules are defined, the 'next_method()' in
> 'pretty_specific()' can change its meaning in unpredictable ways.  E.g.
>
>     multi.remove_rule((Foo,))
>
> Changes the whole thing.  Maybe even the type of value returned by the
> 'next_method()' call.  If "more stuff" depends on that value...
>

It really seems that the notion of multiple dispatching fill your mind with
FUD <wink>.
Your line of reasoning could be equally applied to single dispatch:

we don't write thing as:

def Amethod(self,...):
 ...

class A:
   method = Amethod

class B(A):

  def method(self,...):
     ...
    Amethod(self) # it is not in general the same thing as A.method even
less as super(B,self).method
    ...

Btw  Damian Conway support this <wink>, so CLOS, Dylan, Cecil





















More information about the Python-list mailing list