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

Exercise 3.58 · 习题

Exercise 3.58: Give an interpretation of the
stream computed by the following procedure:

(define (expand num den radix)
(cons-stream
(quotient (* num radix) den)
(expand (remainder (* num radix) den)
den
radix)))

(Quotient is a primitive that returns the integer quotient of two

integers.) What are the successive elements produced by (expand 1 7

10)? What is produced by (expand 3 8 10)?

练习 3.58:解释以下过程所计算的流的含义:

(define (expand num den radix)
(cons-stream
(quotient (* num radix) den)
(expand (remainder (* num radix) den)
den
radix)))

(Quotient 是一个基本过程,返回两个整数相除的整数商。)(expand 1 7 10) 依次产生哪些元素?(expand 3 8 10) 产生什么?

Racket #lang sicp
(define (expand num den radix)
 (cons-stream
 (quotient (* num radix) den)
 (expand (remainder (* num radix) den)
 den
 radix)))