week5b_sol

week5b_sol - CS61A Notes Week 5b(solutions Metacircular...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS61A Notes – Week 5b (solutions): Metacircular evaluator Meta-metaevaluation QUESTION Write lookup-variable-value , which takes a variable and starting environment and returns the value associated with the variable or an error if it isn't found after the global environment. (define (lookup-variable-value var env) (define (env-loop env) (define (scan vars vals) (cond ((null? vars) (env-loop (enclosing-environment env))) ((eq? var (car vars)) (car vals)) (else (scan (cdr vars) (cdr vals))))) (if (eq? env the-empty-environment) (error "Unbound variable" var) (let ((frame (first-frame env))) (scan (frame-variables frame) (frame-values frame))))) (env-loop env)) Regular Metaevaluation QUESTIONS 1. (define (eval-assignment exp env) (set-variable-value! (assignment-variable exp) ;; (cadr exp) (mc-eval (assignment-value exp) env) ;; (caddr exp) env) 'okay) Modify your lookup-variable-value code above to create set-variable-value! (which takes an additional value argument). If we find the variable, instead of returning the corresponding value, we should change it: ... ...
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 2

week5b_sol - CS61A Notes Week 5b(solutions Metacircular...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online