Multiple dispatch again

Samuele Pedroni pedronis at bluewin.ch
Thu Jan 2 15:24:02 EST 2003


"Anders J. Munch" <andersjm at inbound.dk> ha scritto nel messaggio
news:4S0R9.23646$Hl6.2445570 at news010.worldonline.dk...
> "Samuele Pedroni" <pedronis at bluewin.ch> wrote:
> >
> > > Suit yourself.  I have no particular need to convince you; I used the
> > > example for illustration, not as evidence.
> > >
> >
> > where's inspector in your reformulation?
>
> Oh, you're right, I read the original to hastily, focused on
> next-method and missed the role of the inspector subtype completely.
> I'm used to argument types being a mostly-redundant mechanism for
> catching errors, not a mechanism for specifying execution semantics.
>
> I'll try again: The specs say:
> "However, different types of vehicle inspectors may have different
> policies."
>
> def inspect(car, inspector):
>     for inspection in vehicle.relevant_inspections():
>         if inspector.policy_includes(inspection):
>             inspection.perform(vehicle)
>
> My, that was hard.  The lack of multimethods forced me add an entire
> if-statement ;-)

The results of relevant_inspections and the bodies of policy_includes are
not orthogonal, so that's far from ideal.

Are you sure you have illustrated what you wanted to illustrate?

I would go for:

for inspection in relevant_inspections(car,inspector): # multi method
 ...

and use a union combination or filter the results through the super-call
chain.

Nevertheless the example is too much a toy to show anything for whatever
side.

You could try with something larger.

Thanks.









More information about the Python-list mailing list