sicp-ex-5.39



<< Previous exercise (5.38) | Index | Next exercise (5.40) >>


meteorgan

  
  
 (define (lexical-address addr-frame addr-offset) 
  (cons addr-frame addr-offset)) 
 (define (addr-frame address) (car address)) 
 (define (addr-offset address) (cdr address)) 
  
 (define (lexical-address-lookup env address) 
  (let* ((frame (list-ref env (addr-frame address))) 
             (value (list-ref (frame-values frame) (addr-offset address)))) 
   (if (eq? value '*unassigned*) 
           (error "the variable is unassigned -- LEXICAL-ADDRESS-LOOKUP" address))) 
           value) 
  
  
 (define (lexical-address-set! env address value) 
  (let ((frame (addr-frame address)) 
            (offset (addr-frame address))) 
   (define (set-value! f pos) 
    (if (= f 0) 
            (set-car! f value) 
            (set-value! (cdr f (- pos 1))))) 
   (set-value! frame offset value)))