function operators

James A. H. Skillen jahs at jahs.org
Tue Nov 27 20:10:42 EST 2001


On Tue, 27 Nov 2001 01:43:34 +0000, James A. H. Skillen wrote:

Thanks for the feedback from everyone.
Perhaps I should have made it clear: yes, I realise that my suggestions
can be done quite easily using classes and the magic methods.

But any simplicity gained would be offset by the added hassle of wrapping
the functions with instances.

I was just suggesting that __add__ etc. should be implemented for the
built-in "function" type.

I can't see that it would make Python code that much harder to read,
indeed it would simplify things in many cases.

There would be no ambiguity with classes that define both __call__ and
__add__, as 

    f = a + b

would *always* mean

    f = a.__add__(b).

It would be up to the author whether to define __add__ to be equivalent
to:

    f = lambda x: a(x) + b(x).

--
James A. H. Skillen - jahs at jahs.org
4th year MMath Mathematics undergraduate,
University of Warwick, UK.



More information about the Python-list mailing list