Chapter 3, Modularity, Objects, and State
Exercise 3.64
1
2
3
4
5
6
(define (stream-limit s tolerance)
(let ((x1 (stream-car s))
(x2 (stream-car (stream-cdr s))))
(if (< (abs (- x2 x1)) tolerance)
x2
(stream-limit (stream-cdr s) tolerance))))
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1 ]=> (sqrt 4.0 0.0000001)
;Value: 2.000000000000002
1 ]=> (sqrt 4.0 0.0000000000000000000000000000001)
;Value: 2.
1 ]=> (sqrt 2 0.0000000000000000000001)
;Value: 1.414213562373095
1 ]=> (* (sqrt 2 0.0000000000000001) (sqrt 2 0.00000000000001))
;Value: 1.9999999999999996