ClosureClosures for Ring

API reference

The functions and the class of the library.

Functions#

FunctionDescription
closure(aVars, fFunc)Create a closure. aVars is a list of the variables to keep (see below), fFunc is the function to run (usually an anonymous function). Returns a closureObject. Raises an error if aVars is not a list, if fFunc is not a function, or if an item of aVars is not a name or a [name, value] list
invoke(oClosure)Call the closure and return the value that its function returns
isClosure(oVar)Return true if the value is a closure (an object of the class closureObject)

The variables list#

Each item of aVars is one of:

ItemMeaning
:x or "x"Keep the variable x: its value in the function that calls closure() is copied into the closure
[:x, value]Keep a variable x that starts with the given value

Inside the function of the closure the variables are used by their names, and the changes are kept for the next call.

closureObject class#

MemberDescription
fFuncThe function of the closure
invoke()Run the function in the scope of the object, so it can use and change the variables of the closure; returns its result
Closure - Closures for Ring, made with ringdoc.