Exercise 1.5

Given the following two procedures:

1
2
3
4
5
6
(define (p) (p))

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

What is the result of evaluating

1
(test 0 (p))

using the following two substitution models.

Applicative-order evaluation evaluates all the expression arguments and then applies:

1
2
3
4
5
(test 0 (p))
(test 0 (p))
.
.
.

The evaluation enters into an infinite loop since the second expression argument is evaluated to itself.

Normal-order evaluation substitutes operand expressions for parameters until it obtains an expression involving only primitive operators:

1
2
3
4
5
6
7
8
9
(test 0 (p))

(if (= 0 0)
    0
    (p))

(if #t 0 (p))

0

Value: 0

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 2.0 UK: England & Wales License.

Tags: ,

Leave a Reply

CAPTCHA Image

Powered by WP Hashcash

Please wrap all source codes with [code][/code] tags.