Specification

Values

Expressions

Procedure Application

;; 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))))))

Interpreter

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)))
	...)

Determining References

The procedure value-of-operand checks to see if the operand is a variable.

;; 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))))))