【SICP练习】147 练习4.3
2015-03-29 19:35
176 查看
练习4-3
原文
Exercise 4.3. Rewrite eval so that the dispatch is done in data-directed style. Compare this with the datadirected differentiation procedure of exercise 2.73. (You may use the car of a compound expression as the type of the expression, as is appropriate for the syntax implemented in this section.) .分析
参照练习2.73即可。(define operation-table make-table) (define get (operation-table 'lookup-proc)) (define put (operation-table 'insert-proc)) (put 'op 'quote text-of-quotation) (put 'op 'set! eval-assignment) (put 'op 'define eval-definition) (put 'op 'if eval-if) (put 'op 'lambda (lambda (x y) (make-procedure (lambda-parameters x) (lambda-body x) y))) (put 'op 'begin (lambda (x y) (eval-sequence (begin-sequence x) y))) (put 'op 'cond (lambda (x y) (evaln (cond->if x) y))) (define (evaln expr env) (cond ((self-evaluating? expr) expr) ((variable? expr) (lookup-variable-value expr env)) ((get 'op (car expr)) (applyn (get 'op (car expr) expr env))) ((application? expr) (applyn (evaln (operator expr) env) (list-of-values (operands expr) env))) (else (error "Unkown expression type -- EVAL" expr))))
感谢您的访问,希望对您有所帮助。
欢迎大家关注或收藏、评论或点赞。
为使本文得到斧正和提问,转载请注明出处:
http://blog.csdn.net/nomasp
相关文章推荐
- 【SICP练习】147 练习4.3
- SICP题解----第1.1节练习
- 【SICP练习】4 练习1.8
- 【SICP练习】45 练习2.4
- 【SICP练习】127 练习3.58
- 【SICP练习】5 练习1.9
- 【SICP练习】42 练习2.1
- 【SICP练习】142 练习3.77
- 【SICP练习】64 练习2.35
- 【SICP练习】29 练习1.35
- 【SICP练习】121 练习3.52
- 【SICP练习】81 练习2.53
- 【SICP练习】13 练习1.19
- 【SICP练习】20 练习1.26
- 【SICP练习】29 练习1.35
- 【SICP练习】46 练习2.5
- 【SICP练习】50 练习2.18
- 【SICP练习】66 练习2.37
- 【SICP练习】94 练习2.67
- SICP 练习1.7