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

  • 相关阅读:
    ActiveReports打印的问题
    HTML高级应用
    一些常用的asp.net技巧焦点篇
    数据库操作
    [ASP.NET]在后台引用JavaScript
    点击TextBox复制其中内容
    VB.Net基本语句(推荐)
    ADO 对象
    控件不获得焦点
    32款网站优化工具
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7343891.html
Copyright © 2011-2022 走看看