Exercise 5.41. Write a procedure find-variable that takes as arguments a variable and a compile-time environment and returns the lexical address of the variable with respect to that environment. For example, in the program fragment that is shown above, the compile-time environment during the compilation of expression is ((y z) (a b c d e) (x y)). Find-variable should produce (find-variable 'c '((y z) (a b c d e) (x y))) (1 2) (find-variable 'x '((y z) (a b c d e) (x y))) (2 0) (find-variable 'w '((y z) (a b c d e) (x y))) not-found ———————————————————————————————————————————————————————————————————————— For reference, lookup-variable-value from ch5-eceval-support.scm: (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)) --- (define (find-variable var env) (define (env-loop env-index env) (define (scan frame-index vars vals) (cond ((null? vars) (env-loop (+ env-index 1) (enclosing-environment env))) ((eq? var (car vars)) (make-lexical-address env-index frame-index)) (else (scan (+ frame-index 1) (cdr vars) (cdr vals))))) (if (eq? env the-empty-environment) 'not-found (let ((frame (first-frame env))) (scan 0 (frame-variables frame) (frame-values frame))))) (env-loop 0 env)) (define make-lexical-address list)