You are on page 1of 12

The Environment Model

An expression acquires a meaning


only w.r.t some environment in which
it is evaluated

ENVIRONMENTS
In the presence of assignment, a variable can no longer be considered
to be merely a name for a value. Rather, a variable must somehow de
signate a ``place in which values can be stored. These places will be
maintainted in structures called environments.
An environment is a sequence of frames.
Frames:
1. Each frame is a table (possibly empty) of bindings, which associate variable na
mes with their corresponding values
2. Each frame also has a pointer to its enclosing environment (except the global
frame)

GLOBAL ENVIRONMENT : (FA

ENVIRONMENT E1 : (FB, FA)

ENVIRONMENT E2 : (FC, FB, FA

ENVIRONMENT E3 : (FD, FB, FA

The Environment Model


What is means to apply a compound procedure to arguments?
[THE CREATION] A procedure = A pair, consisting of
1. some code (obtained from the text of the lambda expression
2. (a pointer to) an environment in which the lambda expression was e
valuated to produce the procedure.

[THE APPLICATION]
. To apply a procedure to arguments, create a new environment contai
ning a frame that binds the parameters to the value of the arguments.
The enclosing environment of this frame is the environment specified
by the procedure.

PROCEDURE good-enough?s
Environment = E1 : (FB, FA)

(define ...)

1. procedure object
global env
2. ``define make-withdraw
procedure object

(define..)

1. (make-withdraw
100) : E1
(formal
parameter=100)
frame make-withdraw
(global env)
procedure
object
2. ``define W1
procedure object

(W1 50)

1. (W1 50) :
(amount=50) frame
W1 (E1)
50

(set! ..)

1. ``set! E1

(define..)

1. (W2, E2) (E2)


procedure object
2. W1 W2 CODE

You might also like