Page:Scheme - An interpreter for extended lambda calculus.djvu/23



evaluates to

When a closure is to be applied to some arguments:

this is performed by reducing the application expression to

That is, any free variables in the closed lambda expression refer to the environment as of the time of closure, not as of the time of application , whereas the arguments are evaluated in the application environment as expected.

This notion of closure has gone by many other names in other contexts. In LISP, for example, such a closure has been traditionally known as a funarg. ALGOL has several related ideas. Every ALGOL procedure is, at the time of its invocation, essentially a "downward funarg". In addition, expressions which are passed by name instead of by value are closed through the use of mechanisms called thunks [Ingerman]. It turns out that an actor (other than a cell or a serializer) is also a closure. Hewitt [Smith and Hewitt] describes an actor as consisting of a script, which is code to be executed, and a set of acquaintances, which are other actors which it knows about. We contend that the script is in fact identical to the lambda expression in a closure, and that the set of acquaintances is in effect an environment. As an example, consider the following code for cons; taken from [Smith and Hewitt] (cf. [Fischer]):

When the form  is evaluated, the result is an (evaluated)   statement, which is a receiver ready to accept a message such as " " or " ". This resulting receiver evidently knows about the actors  and   as being bound to the variables   and  ; it is evidently a closure of the   script plus a set of acquaintances which includes   and   (as well as " " and " " and " ", for example; PLASMA considers such "constant acquaintances" to be part of the set, whereas in SCHEME we might prefer to consider them part of the script). Once we realize that it is a closure and nothing more, we can see easily how to express the same semantics in SCHEME: