内容 4.2 Variations on a Scheme — Lazy Evaluation · 333
练习 自检推理
Exercise 4.25: Suppose that (in ordinary
applicative-order Scheme) we define unless as shown above and then
define factorial in terms of unless as
(define (factorial n)
(unless (= n 1)
(* n (factorial (- n 1)))
1))
What happens if we attempt to evaluate (factorial 5)? Will our
definitions work in a normal-order language?
练习 4.25:假设(在普通的应用序 Scheme 中)我们按上文定义了 unless,然后用 unless 来定义阶乘:
(define (factorial n)
(unless (= n 1)
(* n (factorial (- n 1)))
1))
如果我们尝试对 (factorial 5) 求值,会发生什么?这些定义在正则序语言中能正常工作吗?
SICP source code scheme
(define (factorial n)
(unless (= n 1)
(* n (factorial (- n 1)))
1)) 我的笔记 自动保存