Re: Overloading function calls

Guido.van.Rossum@cwi.nl
Tue, 07 Jun 1994 11:15:10 +0200

> Under the alternative scheme, Complex.__div__(Date) is invoked, figures
> out it doesn't know what to do, invokes Date.__div__(Complex,1), which
> figures out it doesn't know what to do either, and ...? Probably
> reinvokes Complex.__div__(Date)! I.e., Date doesn't know Complex already
> tried it, and the first three cheap schemes you think of for _letting_ it
> know have subtle fatal flaws <wink>.

No, Date.__div__ sees the swapped flag and knows that the unswapped
operation has already been tried.

In general I'm wary of routines that take flags (such as 'swapped')
that really mean "use a different version of the function" -- these
flags are almost always passed from constants and so it would be more
efficient to have a second name for the variant function.

So my counter proposal would be to define __rbinop__ for every binop
where the RHS wants control. Note that for reflexive binop, adding
__rbinop__ = __binop__ to the class is sufficient. The RHS dispatch
case would then be reduced to a single lookup as well.

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>