Exercise 1.5: Ben Bitdiddle has invented a test to determine whether the in- terpreter 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)

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.)

(test 0 (p)) gives 0 if normal-order is used; the program hangs if applicative-order is used.

Because (p) is pointed to itself which introduces an infinite interpretation loop. And in normal-order the error will have no chance to expose since the 0 circuit is triggered first.

Notice: This Gitbook uses klipse plugin to run the inlined scheme code, and under the hood it uses biwascheme to interpret the code, which is actually using applicative-order, so I disabled the running for

(test 0 (p))

For more information, see this issue: https://github.com/biwascheme/biwascheme/issues/214

results matching ""

    No results matching ""