On Thu, 26 Jan 2012, Mouse wrote:
Loosely put, closures take a blob of code and the
bindings of some
variable names to variables and return a thing which can be executed
like the blob of code, but, while it's executing the code, the
name<->variable mappings saved in the closure are temporarily
reinstated. This means they can be useful when you want to package up
some code along with some state for it to operate on but would rather
not resort to global variables.
In other words, "static local variables"?
In languages without closures, this
can lead to the "callback function and its argument" pattern, but that
has problems when you want to pass two arguments, or you want to share
the state among multiple functions.