Lambda Expression

Lambda expression is a function definition with only one statement.

Syntax

def <functionName>(parameters): expression

or

def (parameters): expression

or

def (parameters) -> expression

or

parameter -> expression

Details

Note that the second and third case in the syntax are also anonymous functions.

The last case in the syntax applies when there is only one parameter.

Examples

def f(x):x pow 2 + 3*x + 4.0;
f(2);
// output
14

def orderby(x,y): x[isort y];
t=table(3 1 7 as id, 7 4 9 as value);
orderby(t, t.id);
id value
1 4
3 7
7 9
each(def(a,b):a+b, 1..10, 2..11);
// output
[3,5,7,9,11,13,15,17,19,21]

g = def (x,y) -> log(x) + y pow 2;
g(e,0);
// output
1

each(x->x+1,1 3 5)
// output
[2,4,6]