[Python-ideas] Lambda again: Anonymous function definition
Matt Chisholm
matt-python at theory.org
Thu Apr 3 02:49:49 CEST 2008
On Mon, 31 Mar 2008 08:19:35, Eli Courtwright wrote:
>On Mon, Mar 31, 2008 at 3:23 AM, Leszek Dubiel <leszek at dubiel.pl> wrote:
>
>> Lambda should have the same syntax as ordinary functions. The only
>> difference should be: you don't have to put the name of the function.
>>
>> def f (x, y): return x ** 2 + y ** 2
>>
>> g = f
>>
>> h = def (x, y): return x ** 2 + y ** 2
>>
>> Functions f, g and h are doing the same.
>
>
>
>Javascript handles anonymous functions this way as well:
>
>function f(x, y) { return x*x + y*y; }
>
>g = f;
>
>h = function(x, y) { return x*x + y*y; }
>
>With that being said, it makes sense for the return statement to be omitted
>in lambdas (or anonymous defs, as I hope they will eventually be called),
>since those functions are limited to one statement.
>
>- Eli
+1 to handling anonymous functions/lambdas the way JavaScript does.
It's the only thing I like better about JavaScript than Python.
I don't know if I agree about leaving off the return statement, though.
-matt
More information about the Python-ideas
mailing list