Anonymous functions are written using LAMBDA(PARAM(...), ...) ===> rhs
:
LAMBDA(PARAM("x")) ==> (REF("x") INT_+ LIT(1))
LAMBDA(PARAM("x", IntClass)) ==> BLOCK(
REF("x") INT_+ LIT(1))
These examples print as:
x => x + 1
{ (x: Int) =>
x + 1
}
As the second example shows, when the right-hand side tree is a block, the entire anonymous function is wrapped in a block, which makes it convenient to be used with higher-order functions.
The parameter list of anonymous functions may be WILDCARD
:
LAMBDA(PARAM(WILDCARD)) ==> (REF("x") INT_+ LIT(1))
This prints as:
_ => x + 1
In addition, an anonymous functions are formed when an expression contains WILDCARD
.
WILDCARD INT_+ WILDCARD // _ + _