Next: CLAM Pattern
Up: General Programming Patterns and
Previous: General Programming Patterns and
Contents
Closure Pattern
The most fundamental of the general programming
patterns derived from ARS is the closure pattern.
A
closure is an encapsulation of a lambda
abstraction with its total environment.
This
environment consists of all the names
that this lambda abstraction has
access to. Access to names in a lambda abstraction is
controlled by the so called `lexical scope'.
Lexical scope can also be described as the
context of a lambda abstraction in the program text.
A closure is a first class object, which
means that it can be treated like any data item:
- it can be stored in memory,
- it can be passed as an argument to a function and
- it may be returned as a value from a function.
The slight difference between a closure and an object
in OOP is the following:
- A closure is essentially a function
that can be called, but may have all kinds of
data and procedures encapsulated in it.
- An object is essentially a data
item with all kinds of data and procedures
encapsulated in it. One of its procedures
(normally called methods) may be `apply',
allowing to apply the object to a set of
arguments, which essentially is the same as
calling a function.
Next: CLAM Pattern
Up: General Programming Patterns and
Previous: General Programming Patterns and
Contents
Start
Georg P. Loczewski
2004-03-05