zoukankan      html  css  js  c++  java
  • 【SICP练习】148 练习4.4

    练习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柯于旺 原创文章,如需转载请联系本人。

  • 相关阅读:
    Scrapy选择器和持久化
    SQLAlchemy
    Python数据库连接池DBUtils
    flask应用上下文和g
    flask请求上下文源码解析
    flask的session源码流程和第三方组件
    430软狗不喂狗后系统起不来的问题
    VS2008 快捷键大全
    未能加载或程序集“XXXX,Version=0.0.0.0,Culter=neutral,PublicKeyToken=null”或它的某一个依赖项。试图加载格式不正确的程序。
    用vs2008打开vs2005项目
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786050.html
Copyright © 2011-2022 走看看