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))
Were this interpreter normal-order evaluation the function would return 0 as it would substitute the if statement in for test, evaluate the equality test, and then return.
Were the interpreter using applicative-order evaluation, it would substitute the two arguments in for test (0 and (p)) and then attempt to evaluate both. That (p) calls itself recursively forever an applicative-order evaluation of this function for the given input would loop forever.
No comments:
Post a Comment