Closure

closure1 = [’^’ [‘_ws] [expression ws]] [parameters ws] code-block
closure-tail-args2 = ws send-args ws closure [ws;ws return-args]
invoke-class3 = [‘_’ | ‘+’] parameters

A doc entry on closures is on its way – until then check out this entry on closures in the forum.

  1. [Also known as: code block, anonymous function or lambda expression.] Optional ‘^’ or parameters or both must be provided (unless used in closure-tail-args where both are optional). Optional expression (which may not be code-block or closure) will be captured and used as receiver/this for the code-block – if not provided this is inferred. Optional ‘_’ indicates it is durational (like a coroutine) – if not present durational/immediate inferred via code-block. Parameter types, return type, scope, whether surrounding this or temporary/parameter variables are used and captured may all be inferred if omitted.

  2. Routines with last send parameter as mandatory closure may omit brackets ‘()’ and closure arguments may be simple code-block (omitting ‘^’ and parameters and inferring from argument parameter context). Default arguments indicated via comma ‘,’ separators.

  3. _’ indicates durational (like coroutine), ‘+’ indicates durational or immediate (coroutine or method) and lack of either indicates immediate (like method). Class ‘Closure’ matches any closure interface. Identifiers and defaults used for closure arguments without parameters.