1 ]=> (load "streams.txt") ;Loading "streams.txt"... done ;Value: stream-enumerate-interval 1 ]=> (define sum 0) ;Value: sum 1 ]=> (define (accum x) (set! sum (+ x sum)) sum) ;Value: accum 1 ]=> (display sum) 0 ;Unspecified return value 1 ]=> (define seq (stream-map accum (stream-enumerate-interval 1 20))) ;Value: seq ; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ; -> 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 1 ]=> (display sum) 1 ;Unspecified return value 1 ]=> (define y (stream-filter even? seq)) ;Value: y ; 1 6 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 ; -> 6 10 28 36 66 78 120 136 190 210 1 ]=> (display sum) 6 ;Unspecified return value 1 ]=> (define z (stream-filter (lambda (x) (= (remainder x 5) 0)) seq)) ;Value: z ; 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 ; -> 10 15 45 55 105 120 190 210 1 ]=> (display sum) 10 ;Unspecified return value 1 ]=> (stream-ref y 7) ;Value: 136 1 ]=> (display sum) 136 ;Unspecified return value 1 ]=> (display-stream z) 10 15 45 55 105 120 190 210 ;Unspecified return value 1 ]=> (display sum) 210 ;Unspecified return value If delay did not cache expression results, the multiple accesses to seq would cause the elements to be recomputed. Because accum has the side effect of increasing sum, the recomputed values will always be greater than the previous ones. Because y and z are filtered views of seq, their element values will increase with each access too.