
Exercise 1.20
The process that a procedure generates is of course dependent on the rules used by the interpreter. As an example, consider the iterative gcd procedure given above. Suppose we were to interpret this procedure using normal-order evaluation, as discussed in Section 1.1.5. (The normal-order-evaluation rule for if is described in Exercise 1.5.) Using the substitution method (for normal order), illustrate the process generated in evaluating (gcd 206 40) and indicate the remainder operations that are actually performed. How many remainder operations are actually performed in the normal-order evaluation of (gcd 206 40)? In the applicative-order evaluation?
Ans
使用的程序
1 |
(define (gcd a b) |
应用序
1 |
(gcd 206 40) |
共 5 次
正则序
1 |
(gcd 206 40) |
总共: t1 一次, t2 一次, t3 两次, t4 一次
t1 调用 remainder 1 次, t2 调用 remainder 2 次, t3 调用 remainder 4 次, t4 调用 remainder 7 次.
所以总共调用 remainder 的次数为:$1+2+4*2+7=18$次




近期评论