def() ... end

Function objects, or closures, can be constructed on the fly using the 'def' keyword. Unlike function and method definitions, they do not require a function name.

formula = def( x, y )
    return x + y*2

n =[ 3, 4 ])


Function objects are also created when you catch a 'block' in a function. To capture a block you use the ampersand for the last parameter.

def foo( a, b, c, &block )
    // omitted

foo( 1, 2, 3 ) do
    console( 'output from the block' )

If a block was provided, using the 'do' syntax, then a Function object is created and passed in.

If no block was provided, then the 'block' parameter will be null.

new Function() { ... }

You can also create functions by calling 'new Function', and attaching the block. The contents of the block is executed when the function is called.

This is essentially the same as using the 'def' keyword, and is only supported for API consistency.