[an error occurred while processing this directive]

cs150: Notes 21

Assignments Due

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:

  1. Construct a new environment, whose parent is the environment to which the environment pointer of the applied procedure points.
  2. Create a place in the frame of the new environment for each parameter containing the value of the corresponding operand expression.
  3. Evaluate the body of the procedure in the newly created environment. The resulting value is the value of the application.
(define double 
   (lambda (x) (+ x x)))



(define nest 
  (lambda (x)
    (lambda (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))
           (evaluate-name name 
             (parent-environment 
                (get-frame env))))))
[an error occurred while processing this directive]