zoukankan      html  css  js  c++  java
  • SICP-Exercise 1.5

    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为正则序

  • 相关阅读:
    LAMP网站架构解释
    ftp--pureftpd1.0.46
    给远程主机起别名
    ssh修改端口号并进行远程访问
    ssh使两台机器建立连接
    Linux搭建svn服务
    centos上git搭建
    centos上Jenkins搭建
    kvm安装准备
    服务器Java环境配置
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7343891.html
Copyright © 2011-2022 走看看