Skip to content

Instantly share code, notes, and snippets.

@ragnard
Last active August 11, 2017 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ragnard/03720fe76618a6c84eff29f48fe77da3 to your computer and use it in GitHub Desktop.
Save ragnard/03720fe76618a6c84eff29f48fe77da3 to your computer and use it in GitHub Desktop.

Arity and dispatch

  • 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

InvokeNode

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment