SICP Exercise 4.4
来源:互联网 发布:js 枚举 编辑:程序博客网 时间:2024/05/21 17:50
SICP Exercise 4.4
a)因为数据导向的方式增加起来比较方便,所以我们继续采用联系4.3中的方式:
(define (eval-and exp env) (define (and-loop exps env) (if (null? exps) true (if (eval (car exps) env) (and-loop (cdr exps) env) false))) (and-loop (cdr exp) env))(define (eval-or exp env) (define (or-loop exps env) (if (null? exps) false (if (eval (car exps) env) true (or-loop (cdr exps) env)))) (or-loop (cdr exp) env))然后就是把这两个过程添加到求值表中即可:
(put 'and eval-and)(put 'or eval-or)b)下面采用派生表达式的方式实现and和or:
(define (and->if exp) (define (expand-clauses clauses) (if (null? clauses) true (let ((first (car clauses)) (rest (cdr clauses))) (make-if first (expand-clauses rest) false)))) (expand-clauses (cdr exp)))(define (eval-and exp env) (eval (and->if exp) env))(define (or->if exp) (define (expand-clauses clauses) (if (null? clauses) false (let ((first (car clauses)) (rest (cdr clauses))) (make-if first true (expand-clauses rest))))) (expand-clauses (cdr exp)))(define (eval-or exp env) (eval (or->if exp) env))测试结果如下:
;;; M-Eval input:(and true true false);;; M-Eval value:#f;;; M-Eval input:(or false true);;; M-Eval value:#t
- SICP Exercise 4.4
- SICP exercise 1.43
- SICP Exercise 3.11
- SICP Exercise 3.15
- SICP Exercise 3.22
- SICP Exercise 3.25
- SICP Exercise 3.28
- SICP Exercise 3.29
- SICP Exercise 3.33
- SICP Exercise 3.34
- SICP Exercise 3.35
- SICP Exercise 3.37
- SICP Exercise 3.38
- SICP Exercise 3.50
- SICP Exercise 3.51
- SICP Exercise 3.52
- SICP Exercise 3.53
- SICP Exercise 3.54
- WCF一步一步往前爬(四)
- V880刷机方法
- Jsp/Servlet读书笔记(二) -- HttpServletRequest和HttpServletResponse
- 深度解析Oracle ERP系统模块
- hdu 1698 Just a Hook(成段更新)
- SICP Exercise 4.4
- Hadoop namenode 不能启动解决方案
- iPhone开发经典语录集锦
- oracle 表中的rowid是什么意思
- 海量数据处理面试题
- linux环境QT安装手册
- android 中判断WiFi是否可用的可靠方法
- 终于可以写blog了
- Linux的RCU锁机制