Practice 4.14
以下面的例子说明 (eval ‘(map + ‘(1 2 3) ‘(4 5 6)) env)
(apply-new (eval 'map env) (list-of-values '(+ '(1 2 3) '(4 5 6)) env))
(list-of-values '(+ '(1 2 3) '(4 5 6)) +是variable, look-up-variable-value返回+的primitive过程'('primitive +), ''(1 2 3)是quote, 返回'(1 2 3), ''(4 5 6)返回'(4 5 6),
(apply-new (eval 'map env) '('('primitive +) '(1 2 3) '(4 5 6)))
如果map是自定义过程
(define map (lambda (op . args)
...map-body))
先求值上面的表达式 (eval-definition exp env) (define-variable! ‘map (eval map-lambda env) env)
(define-variable! 'map map-procedure env)
把map的绑定加入到当前frame中
(eval 'map env)
‘map是variable, lookup-variable-value返回map-procedure
(apply-new map-procedure '('('primitive +) '(1 2 3) '(4 5 6)))
map-procedure是compound-procedure,
eval-sequence正常执行, 递归的eval, 遇到'('primitive +)可以找到正确的过程+
如果map是primitive过程 (apply-new ‘(‘primitive map) ‘(‘(‘primitive +) ‘(1 2 3) ‘(4 5 6))) (apply map ‘(‘(‘primitive +) ‘(1 2 3) ‘(4 5 6)))
apply将map应用于 ‘(‘(‘primitive +) ‘(1 2 3) ‘(4 5 6)) 求值过程就变成了 (map ‘(‘primitive +) ‘(1 2 3) ‘(4 5 6)), 过程map的调用应该是 (map proc list1 list2 …) 这种形式, ‘(‘primitive +)不是一个过程, 所以会出错