Skip to main content

Lambda

A lambda is an anonymous function value. It can be written as a single expression or as a block of statements, and it is invoked with run().

Simple Expressions

  • simple expression: (x, y) ⇒ x+y

Block Statements

(x, y) => {
let a = x + 1
return a + y
} // explicit return is required

the lambda parameter support object/array destructuring:

// obj is a map/object type variable
(obj) => obj.field1 + obj.field2
// OR
({field1, field2}) => field1 + field2

run(lambda, arguments…​)

run lambda function with optional arguments

let printLabel = () => {
printf("hello world")
}
run(printLabel)

let inc = (i) => {
return i+1
}
printf("inc %d", run(inc, 2))