[Oberon] Oberon and closures
Douglas G. Danforth
danforth at greenwoodfarm.com
Wed Oct 29 05:38:48 MET 2008
Martin Bishop wrote:
> Is it possible to create a closure in Oberon? If not, why not? what
> prevent it?
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
From Wikipedia we find
In computer science <http://en.wikipedia.org/wiki/Computer_science>, a
*closure* is a function
<http://en.wikipedia.org/wiki/Function_%28programming%29> that is
evaluated in an environment containing one or more bound variables
<http://en.wikipedia.org/wiki/Bound_variable>. When called, the function
can access these variables. The explicit use of closures is associated
with functional programming
<http://en.wikipedia.org/wiki/Functional_programming> and with languages
such as ML <http://en.wikipedia.org/wiki/ML_programming_language> and
Constructs such as objects
<http://en.wikipedia.org/wiki/Object_oriented_programming> in other
languages can also be modeled with closures.
In some languages, a closure may occur when a function is defined within
another function, and the inner function refers to local variables of
the outer function. At runtime <http://en.wikipedia.org/wiki/Runtime>,
when the outer function executes, a closure is formed, consisting of the
inner function’s code and references to any variables of the outer
function required by the closure.
A closure can be used to associate a function with a set of "private"
variables, which persist over several invocations of the function. The
scope <http://en.wikipedia.org/wiki/Scope_%28programming%29> of the
variable encompasses only the closed-over function, so it cannot be
accessed from other program code. However, the variable is of indefinite
extent <http://en.wikipedia.org/wiki/Variable#Scope_and_extent>, so a
value established in one invocation remains available in the next. As a
consequence, closures can be used to hide state
<http://en.wikipedia.org/wiki/Information_hiding>, and thus to implement
Global variables in an Oberon module act like the bound variables for
every procedure of the module that accesses those variables.
Oberon-2 and Component Pascal allow for functions within functions and
so the above hold for the local variables in the outer
So, yes, you can create a closure in Oberon.
More information about the Oberon