7 (define (make-frame variables values)
8 (if (not (= (length variables)
10 (error "Number of variables and values should be the same -- MAKE-FRAME")
11 (map cons variables values)))
13 (define (frame-variables frame)
16 (define (frame-values frame)
19 (define (add-binding-to-frame! var val frame)
20 (define (add-to-end-of-frame! b f)
23 (add-to-end-of-frame! b (cdr f))))
24 (add-to-end-of-frame! (cons var val) frame))
26 (define (lookup-variable-value var env)
27 (define (env-loop env)
30 (env-loop (enclosing-environment env))
31 (let ((p (car frame)))
34 (scan (cdr frame))))))
35 (if (eq? env the-empty-environment)
36 (error "variable not defined")
37 (let ((f (first-frame env)))
41 (define (set-variable-value! var val env)
42 (define (env-loop env)
45 (env-loop (enclosing-environment env))
46 (let ((p (car frame)))
49 (scan (cdr frame))))))
50 (if (eq? env the-empty-environment)
51 (error "variable not defined")
52 (let ((f (first-frame env)))
56 (define (define-variable! var val env)
57 (let ((frame (first-frame env)))
60 (add-binding-to-frame var val frame)
61 (let ((p (car frame)))
64 (scan (cdr frame))))))