function operators
Hans Nowak
wurmy at earthlink.net
Tue Nov 27 21:47:43 EST 2001
"James A. H. Skillen" wrote:
>
> 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).
Yes, you have a point there. If the author wants his object to behave
like a function, he goes for the lambda, otherwise for the addition.
Well, I don't know. You could write a PEP for this, and see what
Guido thinks about it. Personally, I am reluctant to welcome new
features that can easily be done or emulated in Python itself. So
many redundant features have been added lately... then again, YMMV.
But every new feature is a step closer to creeping featurism and
away from "Python the compact language".
That is not to say that I don't like your idea. Heck, if "".join()
made it into the language, why not this? ;-)
--Hans
More information about the Python-list
mailing list