Exercise 1.5: Ben Bitdiddle has invented a test
to determine whether the interpreter he is faced with is using
applicative-order evaluation or normal-order evaluation. 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 uses applicative-order
evaluation? What behavior will he observe with an interpreter 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 evaluate the consequent or the alternative
expression.)
练习 1.5:Ben Bitdiddle 发明了一种测试方法,用于判断他所面对的解释器使用的是应用序求值还是正则序求值。他定义了以下两个过程:
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
然后他求值表达式
(test 0 (p))
使用应用序求值的解释器会表现出什么行为?使用正则序求值的解释器又会表现出什么行为?请解释你的回答。(假定特殊形式 if 的求值规则无论解释器使用正则序还是应用序都相同:先对谓词表达式求值,其结果决定是对推论表达式还是替代表达式求值。)
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y)) (test 0 (p))