内容 5.5 Compilation · 457
练习 自检推理
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 生成的代码加以比较。解释你发现的任何差异。两个程序中,哪个执行效率更高?
SICP source code scheme
(define (factorial-alt n)
(if (= n 1)
1
(* n (factorial-alt (- n 1))))) 我的笔记 自动保存