Andl now has ‘functions as values’, and lambda literals.
A lambda is the literal form of a value of type ‘function’. It corresponds to a defined function but can be treated as a first class value: it can be
- stored in a variable, component member of a user-defined type or attribute of a tuple
- passed as a parameter
- executed by the postfix operator of parentheses enclosing an argument list.
The syntactic definition is similar to a function definition omitting the name.
// function literal def funlit(def(a:'') => a & a) funlit(‘ab’) // function variable var funval := def def(a:'') => a & a funval(‘ab’) // direct call on function value (def def(a:'') => a & a)(‘ab’)
In this example, funlit, funval and the literal lambda can be called interchangeably. The value can be stored in a variable, user type component or tuple attribute and can be passed as a parameter. There is no type declaration as such, just literals of the type. Treating the function call on values as a postfix operator produces an odd asymmetry:
funval(‘ab’) // legal funlit(‘ab’) // legal (funval)(‘ab’) // legal (funlit)(‘ab’) // illegal! [Built in and user-defined operators are still second class.]
Please note that these are individual function values, not methods. They have access to local and global scope, but there is no object or instance scope.
The latest release provides the working system and samples. Download from github.