Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the DrRacket interpreter use normal-order evaluation based on SICP Exercise 1.5?

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.

like image 737
Geoffrey Avatar asked Dec 12 '10 15:12

Geoffrey


1 Answers

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

like image 70
sepp2k Avatar answered Sep 22 '22 00:09

sepp2k