灯下 登录
计算机科学 / SICP / 5.5.5 An Example of Compiled Code

Exercise 5.33 · 习题

Exercise 5.33: Consider the following definition
of a factorial procedure, which is slightly different from the one given above:

(define (factorial-alt n)
(if (= n 1)
1
(* n (factorial-alt (- n 1)))))

Compile this procedure and compare the resulting code with that produced for

factorial. Explain any differences you find. Does either program

execute more efficiently than the other?

练习 5.33:考虑下面这个阶乘过程的定义,它与上面给出的定义略有不同:

(define (factorial-alt n)
(if (= n 1)
1
(* n (factorial-alt (- n 1)))))

编译这个过程,并将所得代码与为 factorial 生成的代码加以比较。解释你发现的任何差异。两个程序中,哪个执行效率更高?

Racket #lang sicp
(define (factorial-alt n)
 (if (= n 1)
 1
 (* n (factorial-alt (- n 1)))))