内容 3.5 Streams · 277
练习 自检推理
Exercise 3.64: Write a procedure
stream-limit that takes as arguments a stream and a number (the
tolerance). It should examine the stream until it finds two successive
elements that differ in absolute value by less than the tolerance, and return
the second of the two elements. Using this, we could compute square roots up
to a given tolerance by
(define (sqrt x tolerance)
(stream-limit (sqrt-stream x) tolerance))
练习 3.64:编写过程 stream-limit,它以一个流和一个数(容差)为参数。该过程检查流,直到找到两个连续元素的绝对差小于容差,并返回这两个元素中的第二个。利用这个过程,我们可以按给定容差计算平方根:
(define (sqrt x tolerance)
(stream-limit (sqrt-stream x) tolerance))
SICP source code scheme
(define (sqrt x tolerance)
(stream-limit (sqrt-stream x) tolerance)) 我的笔记 自动保存