Question

One must decide, based on the value of:

(test 0 (p))

where test is defined as :

(define (test x y)
  (if (= x 0)
      0
      y))

and p is defined as :

(define (p) (p))

When I evaluate (test 0 (p)) the interpreter goes into an infinite loop, suggesting that it is evaluating p. This shows normal-order evaluation, because the operands are evaluated before being substituted for parameters. SICP says LISP uses applicative-order evaluation.

Was it helpful?

Solution

This shows normal-order evaluation, because the operands are evaluated before being substituted for parameters

Actually you got it the wrong way around. Applicative order is when the operands are evaluated first. Normal-order is when the arguments are substituted into the expression unevaluated.

So racket uses applicative order because as you said the arguments are evaluated first (unless you use "Lazy Racket" in which case it uses call-by-need aka lazy evaluation, which is like normal-order except each argument is evaluated at most once).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top