- functions have a single, known arity
Given a function f
, with arity 3 (lambda (a b c) ...)
, application can be performed in three ways:
partial application: (f 1)
- return curried function with arity 2
exact application: (f 1 2 3)
- invoke function call target with args
"over" application: (f 1 2 3 4 5)
- invoke function with
1 2 3
- expect return to be function
- invoke returned function with remaining arguments
4 5
- repeat until either partial or exact application
Function f = (Function)this.functionNode.executeGeneric(frame)
while (arity of f is less than number of consumed arguments) {
Object[] argumentValues = evaluate and consume arguments needed for function
function = (Function) call(f, argumentValues)
}
if (arity of f is greater than number of arguments) {
return curried version of f
} else {
Object[] argumentValues = evaluate remaining, unconsumed arguments
call(f, argumentValues)
}