Exercise 1.5.  Ben Bitdiddle has invented a test to determine whether the interpreterhe is faced with is using applicative-order evaluation or normal-orderevaluation. He defines the following two procedures:

(define (p) (p))



(define (test x y)

  (if (= x 0)

      0

      y))

Then he evaluates the expression

(test 0 (p))

What behavior will Ben observe with an interpreter that usesapplicative-order evaluation? What behavior will he observe with aninterpreter that uses normal-order evaluation?

Explain your answer.(Assume that the evaluation rule for the special form
if
is the same whether the interpreter is using normal or applicative order:The predicate expression is evaluated first, and the result determines whether to evaluatethe consequent or the alternative expression.)

1、无參数函数

(define (p) (+ 1 2) )

;Value p

p

;Value 18:#[compound-procedure 18 p]

(p)

;Value 3

比較一下:

(define x (+ 1 2) )

;Value x

x

;Value 3

2、无限循环

(define (p) (p))无限循环。前一个(p)定义无參数函数,后一个(p)表示调用自己。

3.应用序和正则序的差别

应用序:(test 0 (p))时,先求值(p)——无限循环,再将(p)的值带入

(if (= x 0)

      0

      y))

正则序:(test 0 (p))时。先带入/展开,即

(if (= x 0)

      0

      (p)))

依照if求值顺序,推断0=0,结果为#t。

注意:if为正则序

SICP-Exercise 1.5的更多相关文章

  1. nomasp 博客导读:Android、UWP、Algorithm、Lisp(找工作中……

    Profile Introduction to Blog 您能看到这篇博客导读是我的荣幸.本博客会持续更新.感谢您的支持.欢迎您的关注与留言.博客有多个专栏,各自是关于 Android应用开发 .Wi ...

  2. sicp第1章

    牛顿迭代法求平方: (define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) ...

  3. SICP 阅读笔记(二)

    Chapter 1: Building Abstractions with Procedures 2015-09-29 016 Preface of this chapter QUOTE: The a ...

  4. Lisp和SICP

         大概不少programmer都看过<黑客与画家>,作者用了整整一章的篇幅讨论Lisp的强大.我自然就会手痒痒.      几个月前,几天内攻城略地搞定了Python,用的方法便是 ...

  5. MIT 6.828 JOS学习笔记12 Exercise 1.9

    Lab 1中Exercise 9的解答报告 Exercise 1.9: 判断一下操作系统内核是从哪条指令开始初始化它的堆栈空间的,以及这个堆栈坐落在内存的哪个地方?内核是如何给它的堆栈保留一块内存空间 ...

  6. MIT 6.828 JOS学习笔记13 Exercise 1.10

    Lab 1 Exercise 10 为了能够更好的了解在x86上的C程序调用过程的细节,我们首先找到在obj/kern/kern.asm中test_backtrace子程序的地址, 设置断点,并且探讨 ...

  7. MIT 6.828 JOS学习笔记11 Exercise 1.8

    Exercise 1.8       我们丢弃了一小部分代码---即当我们在printf中指定输出"%o"格式的字符串,即八进制格式的代码.尝试去完成这部分程序. 解答: 在这个练 ...

  8. MIT 6.828 JOS学习笔记8. Exercise 1.4

    Lab 1 Exercise 4 阅读关于C语言的指针部分的知识.最好的参考书自然是"The C Programming Language". 阅读5.1到5.5节.然后下载poi ...

  9. MIT 6.828 JOS学习笔记9. Exercise 1.5

    Lab 1 Exercise 5 再一次追踪一下boot loader的一开始的几句指令,找到第一条满足如下条件的指令处: 当我修改了boot loader的链接地址,这个指令就会出现错误. 找到这样 ...

  10. MIT 6.828 JOS学习笔记5. Exercise 1.3

    Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...

随机推荐

  1. java 图片数据Base64编解码

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...

  2. ubuntu终止进程的方法

    在ubuntu中,终止一个进程或终止一个正在运行的程序,一般是通过 kill .killall.pkill.xkill 等进行. 先看两个例子: 例子一:结束某个程序,如Firefox  键入命令: ...

  3. 如何自定义oauthauthorizationserverprovider错误信息?

    We are using the OAuthAuthorizationServerProvider class to do authorization in our ASP.NET Web Api a ...

  4. oracle 批量更新表字段

      (一) 将数字替换成汉字 第一步,去重查询 使用distinct关键字先对该字段值进行去重查询,看共有几种情况 --查询指定区间内表停诊字段的值 SELECT DISTINCT T.CLOSE_T ...

  5. 引入css的几种方式

      使用CSS样式的几种方式 CreateTime--2017年10月11日16:45:26 Author:Marydon a.外部样式 a1.链接式(推荐使用) <link href=&quo ...

  6. 〖Linux〗Qt+gsoap开发客户端程序,服务端地址设定的字符串转换处理

    之所以写出来,是由于经常因为这个问题屡屡丢面子.. 一般情况下,QString转换成(char*),我们一般直接使用: char *str = qstr->text().toLatin1().d ...

  7. JAVA中定义常量的几种方式

    1.最古老的 //未处理 public static final Integer PROCESS_STATUS_UNTREATED = 0; //已接收 public static final Int ...

  8. python第三方包的windows安装文件exe格式

    今天弄了一上午的python-ldap,发现要么安装vc,要么用其他比较麻烦的方法,都比较麻烦.幸好找到这个地址: http://www.lfd.uci.edu/~gohlke/pythonlibs/ ...

  9. html5实现全屏的api方法

    参考地址 [进入和退出全屏] // Webkit (works in Safari5.1 and Chrome 15) element.webkitRequestFullScreen(); docum ...

  10. logback+slf4j作为日志系统

    一.logback简介 log4j和logback作者是同一人:CekiGülcü.log4j和logback都是实打实的日志系统. commons-logging,slf4j这两者是日志大管家.sl ...