博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【SICP练习】148 练习4.4
阅读量:5102 次
发布时间:2019-06-13

本文共 1904 字,大约阅读时间需要 6 分钟。

练习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)))))



感谢您的访问,希望对您有所帮助。

欢迎大家关注或收藏、评论或点赞。


为使本文得到斧正和提问,转载请注明出处:


版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

转载于:https://www.cnblogs.com/NoMasp/p/4786050.html

你可能感兴趣的文章
通过管道实现文件的拷贝
查看>>
Android 简单登陆 涉及 Button CheckBox TextView EditText简单应用
查看>>
回溯算法解迷宫问题(java版)
查看>>
微信公共账号学习笔记 _ 感想 爪机码字
查看>>
记一次简单的破解程序(逆向)
查看>>
2016-4-28
查看>>
wechat
查看>>
Python装饰器的原理与应用
查看>>
protobuf(Protocol Buffers)java初体验
查看>>
BC 2015在百度之星程序设计大赛 - 预赛(1)(KPI-树董事长)
查看>>
Matlab实现Hough变换检測图像中的直线
查看>>
UVA 10815 Andy's First Dictionary(字符处理)
查看>>
SEO市场是在扩大还是缩小 Seoer终于会变成什么?
查看>>
php xss过滤
查看>>
5999卖999!是噱头还是颠覆
查看>>
Python重写C语言程序100例--Part6
查看>>
利用vs10和opencv识别图片类型身份证的号码
查看>>
【转载】H264编码原理以及I帧、B帧、P帧
查看>>
【ACwing 95】费解的开关——枚举 + 搜索
查看>>
cookie、sessionStorage、localStorage的区别
查看>>