A lambda is a block of code that maps a variable number of parameters into a single output value of any type (see the Value types section of this wiki).
The syntax is:
param1 param2 param3:
My codeThe param1 param2 param3: portion is the header of the lambda, where you define parameter names. You can access their values as if you were dealing with variables:
param1 param2 param3:
The second parameter is .param2You can omit the header in these cases:
.1, .2, .3, etc.The second parameter is .2Lambdas are constructs that can fork and create new scopes.
Lambdas are defined the same way whether they appear in a block or an inline argument (those wrapped in curly braces). However, for inline arguments, you must add a @lambda instruction at the beginning to help the compiler recognize that it is dealing with a lambda.
.myfunction {@lambda x y: The values are .x and .y}Implicit parameters work as well:
.myfunction {@lambda The values are .1 and .2}This is only needed if you access parameters of the lambda. If the evaluation is constant, you can omit @lambda.
.foreach.foreach {2..5}
n:
The number is **.n**With implicit parameter:
.foreach {2..5}
The number is **.1**.functionThe body of .function is a lambda that accepts a variable amount of explicit parameters:
.function {area}
width height:
.multiply {.width} by:{.height}.takeif.num::takeif {@lambda x: .x::equals {5}}