GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing sicp.sourceacademy.org — 3.2 The Environment Model of Evaluation - SICP Comparison Edition
SICP — Scheme/JS
Structure and Interpretation of Computer Programs — Comparison Edition
Permalink copied!
3.2 The Environment Model of Evaluation
When we introduced compound procedures functions in chapter 1, we used the substitution model of evaluation (section 1.1.5) to define what is meant by applying a procedure function to arguments:
Once we admit assignment into our programming language, such a
definition is no longer adequate. In particular,
section 3.1.3 argued that, in the
presence of assignment,
a variable cannot be considered to be merely a name for
a value. Rather, a variable must somehow designate a
An environment is a sequence of frames. Each frame is a table (possibly empty) of bindings, which associate variable names names with their corresponding values. (A single frame may contain at most one binding for any variable.) (A single frame may contain at most one binding for any name.) Each frame also has a pointer to its enclosing environment, unless, for the purposes of discussion, the frame is considered to be global. The value of a variable value of a name with respect to an environment is the value given by the binding of the variable name in the first frame in the environment that contains a binding for that variable. name. If no frame in the sequence specifies a binding for the variable, name, then the variable name is said to be unbound in the environment.
Figure 3.1 Figure 3.2 shows a simple environment structure consisting of three frames, labeled I, II, and III. In the diagram, A, B, C, and D are pointers to environments. C and D point to the same environment. The variables names z and x are bound in frame II, while y and x are bound in frame I. The value of x in environment D is 3. The value of x with respect to environment B is also 3. This is determined as follows: We examine the first frame in the sequence (frame III) and do not find a binding for x, so we proceed to the enclosing environment D and find the binding in frame I. On the other hand, the value of x in environment A is 7, because the first frame in the sequence (frame II) contains a binding of x to 7. With respect to environment A, the binding of x to 7 in frame II is said to shadow the binding of x to 3 in frame I. The environment is crucial to the evaluation process, because it determines the context in which an expression should be evaluated. Indeed, one could say that expressions in a programming language do not, in themselves, have any meaning. Rather, an expression acquires a meaning only with respect to some environment in which it is evaluated.
3.2 The Environment Model of Evaluation
| ||||||||||||||||||
| You are visitor 01402639 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |