【SICP练习】148 练习4.4
2015-09-08 00:00
429 查看
练习4-4
原文
Exercise 4.4. Recall the definitions of the special forms and and or from chapter 1:● and: The expressions are evaluated from left to right. If any expression evaluates to false, false is returned; any remaining expressions are not evaluated. If all the expressions evaluate to true values, the value of the last expression is returned. If there are no expressions then true is returned.
● or: The expressions are evaluated from left to right. If any expression evaluates to a true value, that value is returned; any remaining expressions are not evaluated. If all expressions evaluate to false, or if there are no expressions, then false is returned.
Install and and or as new special forms for the evaluator by defining appropriate syntax procedures and evaluation procedures eval-and and eval-or. Alternatively, show how to implement and and or as derived expressions.
代码
((and? expr) (evaln (and->if expr) env)) (define (and->if expr) (expand-and-clauses (and-clauses expr))) (define (expand-and-clauses clauses) (if (null? clauses) (make-if 'true 'true 'false) (let ((first (car clauses)) (rest (cdr clauses))) (if (null? rest) (make-if first first 'false) (make-if first (expand-and-clauses rest) 'false))))) ((or? expr) (evaln (or->if expr) env)) (define (or->if expr) (expand-or-clauses (or-clauses expr))) (define (expand-or-clauses clauses) (if (null? clauses) (make-if 'true 'false 'true) (let ((first (car clauses)) (rest (cdr clauses))) (make-if first 'true (expand-or-clauses rest)))))
感谢您的访问,希望对您有所帮助。
欢迎大家关注或收藏、评论或点赞。
为使本文得到斧正和提问,转载请注明出处:
http://blog.csdn.net/nomasp
版权声明:本文为 NoMasp柯于旺 原创文章,未经许可严禁转载!欢迎访问我的博客:http://blog.csdn.net/nomasp
相关文章推荐
- 不要使用CSS Expression的原因分析
- C#窗体编程(windows forms)禁止窗口最大化的方法
- ASP.NET 2.0 中Forms安全认证
- 表格隔行换色 css expression
- Expression Web 2006正式发布
- javascript中expression的用法整理
- document.forms[].submit()使用介绍
- asp.net 基于forms验证的目录角色权限的实现
- html的DOM中document对象forms集合用法实例
- ASP.NET实现基于Forms认证的WebService应用实例
- ASP.NET Internet安全Forms身份验证方法
- (翻译)Java SE 8 Lambda 特性与基本原理(上)
- oracle decode function
- grep技巧 转载
- Linux下find命令错误"find: paths must precede expression"
- vc6-2-expression cannot be evaluated
- stddef.h
- awk中gsub和sub 的用法
- EL表达式
- Expression Designer系列工具汇总 [转载]