Lambda again: Anonymous function definition
Greg wrote:
What's needed is something very concise and unobtrusive, such as
x, y => x + y
As inspired by Prolog:
x, y : x + y
So this:
f = lambda x, y: x ** 2 + y ** 2
Or this:
def f(x, y): return x ** 2 + y ** 2
Becomes this:
f = x, y : x ** 2 + y ** 2
And would logically transpose into this:
f(x, y) : x ** 2 + y ** 2
Oooo...this rabbit hole is fun!
Joel
Joel Bender napisał(a):
Greg wrote:
What's needed is something very concise and unobtrusive, such as
x, y => x + y
As inspired by Prolog:
x, y : x + y
So this:
f = lambda x, y: x ** 2 + y ** 2
Or this:
def f(x, y): return x ** 2 + y ** 2
Becomes this:
f = x, y : x ** 2 + y ** 2
And would logically transpose into this:
f(x, y) : x ** 2 + y ** 2
Oooo...this rabbit hole is fun!
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.
On Mon, Mar 31, 2008 at 3:23 AM, Leszek Dubiel leszek@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
participants (3)

Eli Courtwright

Joel Bender

Leszek Dubiel