[an error occurred while processing this directive]
cs150: Notes 21
- Wednesday, 14 March: Problem Set 5
- Before Monday, 19 March: Read rest of GEB part I (Chapters 2-4 and 6-9, in
addition to Chapters 1 and 5 you have already read).
Evaluation Rules (with state)
Evaluation Rule 2 (with state): Names. A name expression
evaluates to the value associated with the name. To find the value
associated with a name, look for the name in the frame associated with
the evaluation environment. If it contains a place with the name, the
value of the name expression is the value in that place. If it does not
contain a place with the name, the value of the name expression is the
value of the name expression evaluated in the parent environment if the
current evaluation environment has a parent. Otherwise, the name
expression evaluates to an error (the name is not defined).
Definition Rule (with state). A definition creates a new place
named after the definition name in the frame associated with the
evaluation environment. The value in the place is value of the
expression. If there is already a place with the name in the current
frame, the definition replaces the old place with the new place and value.
Application Rule 2 (with state): Constructed Procedures. To apply
a constructed procedure:
- Construct a new environment, whose parent is the environment to
which the environment pointer of the applied procedure points.
- Create a place in the frame of the new environment for each
parameter containing the value of the corresponding operand expression.
- Evaluate the body of the procedure in the newly created
environment. The resulting value is the value of the application.
(lambda (x) (+ x x)))
(+ x x))))
((nest 3) 4)
(define (evaluate-name name env)
(if (null? env) (erro r)
(if (frame-contains name (get-frame env))
(lookup name (get-frame env))