Fep — Anonymous Functions
Anonymous functions are described by the following lexical definitions:
anonfn_longform ::= fn [parameter_list] { expression } anonfn_shortform ::= [parameter_list] => expression
Here are some examples of it in action:
// Example with one parameter. var a = [ 1, 2, "foo" ]; var found = a.find( e => e is FString ); println found; // Prints "foo" // Example with multiple parameters. var adder = (x, y) => x + y; var sum = adder(1, 1); println sum; // Prints "2" // Example with multiple expressions. var complicated = (x, y) => (var z = x + y; z + y) var result = complicated( 1, 2 ); // result has value 5 // Example of a long anonymous function. var long = fn(x, y, z) { var z = x + y; var a = z * z; return a; }; var answer = long( 1, 2, 3 ); // answer has value 9