apply-procedure must change, because it is no longer true that a new location is allocated for every procedure call. That responsibility must be moved upstream, to the call-exp line in value-of, which will have the information to make that decision.;; apply-procedure : Proc × Ref → ExpVal
(define apply-procedure
(lambda (proc1 val)
(cases proc proc1
(procedure (var body saved-env)
(value-of body (extend-env var val saved-env))))))
We then modify the call-exp line in value-of, and introduce a new function value-of-operand that makes the necessary decision.
; modify value-of
(define value-of
...
(call-exp (rator rand)
(let ((proc (expval->proc (value-of rator env)))
(arg (value-of-operand rand env)))
(apply-procedure proc arg)))
...)
The procedure value-of-operand checks to see if the operand is a variable.
apply-procedure.;; value-of-operand : Exp × Env → Ref
(define value-of-operand
(lambda (exp env)
(cases expression exp
(var-exp (var) (apply-env env var))
(else (newref (value-of exp env))))))