<< Previous exercise (3.54) | Index | Next exercise (3.56) >>
Must have self-reference to avoid recalculation:
(define (partial-sums s)
(define ps (add-streams s (cons-stream 0 ps)))
ps)
My solution:
(define (partial-sums S)
(cons-stream (stream-car S)
(add-streams (partial-sums (stream-cdr S))
S)))
dekuofa1995's solution is wrong. For his, (partial-sums integers) returns 1, 3, 7, 12... correct solution should return (partial-sums integers) => 1, 3, 6, 10...
(define (partial-sums s)
(cons-stream (stream-car s)
(add-streams (partial-sums s)
(stream-cdr s))))
(define (partial-sums s) (cons-stream (stream-car s) (add-streams (stream-cdr s) (partial-sums s))))
dzy
this will cause recalculation.