Multiple dispatch again

David Mertz mertz at gnosis.cx
Fri Jan 3 03:56:11 EST 2003


"Samuele Pedroni" <pedronis at bluewin.ch> wrote previously:
|Unless you have only single inheritance and so you don't need
|linearization of class hierarchies, I don't think the weighted
|approach is manageable.

Well...  I think Damian Conway is pretty smart guy.  And the weighted
approach is what he did in his Perl version.  I'm not necessarily in
favor of that linearization over others, but I don't see anything
obviously wrong about it.

|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...

Then again, I am -delighted- to be shown wrong with an example of a
useful use of this sort of thing.

|http://www.dreamsongs.com/NewFiles/ECOOP.pdf

Thanks for this reference.  It's quite interesting.  But I think I'm
more interested in programming (and demonstrating) what is concretely
useful than merely "everything CLOS can do"... y'know what I mean?

Yours, David...

--
---[ to our friends at TLAs (spread the word) ]--------------------------
Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego
White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad
---[ Postmodern Enterprises <mertz at gnosis.cx> ]--------------------------






More information about the Python-list mailing list