next up previous
Next: Macros Up: No Title Previous: Unwind/wind protection

Evaluating computed expressions

The original 1975 memo on Scheme described evaluate, which was analogous to Lisp's traditional eval function. evaluate took a single argument, an S-expression, and invoked an interpreter on it. For example: =0pt=0pt=0pt =0pt[] (let ((name '+)) (evaluate (list name 2 3))) 5

Scheme being lexically scoped, however, there was some confusion over which environment the expression was to be evaluated in. Should =0pt=0pt=0pt =0pt[] (let ((name '+)) (let ((+ *)) (evaluate (list name 2 3))))

evaluate to 5 or to 6?

To clarify matters, the Revised Report replaced evaluate with enclose, which took two arguments, a lambda-expression and a representation of an environment from which to supply bindings of the lambda-expression's free variables. For example: =0pt=0pt=0pt =0pt[] (let ((name '+)) (let ((+ *)) ((enclose (list 'lambda '() (list name 2 3)) (list (cons '+ +)))))) 6

This forced the programmer to be explicit about the lambda-expression's enclosing environment.

For various technical and practical reasons, there was no eval analogue in subsequent Scheme reports. The major stumbling blocks were how to describe eval formally and how to define something that makes sense in all extant variants of the language. Some Scheme implementations contain a distinguished top-level environment, while others extend the language by providing ways to create multiple environments, any of which might serve equally well.

The eval proposal adopted at the June meeting, which I reproduce here, is one that comes from Bill Rozas.

Rozas explains: ``The proposal does not imply the existence or support of first-class environments, although it is compatible with them. The proposal only requires a way of associating tags with a finite set of distinguished environments which the implementations can maintain implicitly (without reification).

```Pascal-like' implementations can support both null-environment and scheme-report-environment since the environments specified by the return values of these procedures need not share any bindings with the current program. A version of eval that supports these but not interaction-environment can be written portably, but can be better written by the implementor, since it can share code with the default evaluator or compiler.''

Here ``Pascal-like'' refers to implementations that are restricted to static compilation and linking. Because an eval that doesn't support

interaction-environment can be written entirely in the Scheme language described by the rest of the report, it raises no troublesome questions about its formal semantics.



next up previous
Next: Macros Up: No Title Previous: Unwind/wind protection



Margaret M Fleck
Tue Nov 5 21:19:46 CST 1996