灯下 登录
计算机科学 / SICP / 3.5.2 Infinite Streams

Exercise 3.54 · 习题

Exercise 3.54: Define a procedure
mul-streams, analogous to add-streams, that produces the
elementwise product of its two input streams. Use this together with the
stream of integers to complete the following definition of the stream
whose n

th element (counting from 0) is n
+
1 factorial:

(define factorials

(cons-stream 1 (mul-streams ⟨??⟩ ⟨??⟩)))

练习 3.54:定义一个过程 mul-streams,类似于 add-streams,它产生两个输入流的逐元素之积。用它与整数流一起,补全以下定义——该流的第 n 个元素(从 0 开始计数)为 n + 1 的阶乘:

(define factorials
(cons-stream 1 (mul-streams ⟨??⟩ ⟨??⟩)))

Racket #lang sicp
(define factorials
 (cons-stream 1 (mul-streams ⟨??⟩ ⟨??⟩)))