Exercise 3.56

It’s not really a good idea to use display-stream to test results since it will never end with infinite streams, so I wrote something to display a certain number of items.

(define (show-stream s n)
  (if (zero? n)
      (display-line "done")
      (begin
        (show (stream-car s))
        (show-stream (stream-cdr s) (- n 1) ))))

(define hammings 
  (cons-stream 
   1 
   (merge (scale-stream hammings 2)
          (merge (scale-stream hammings 3)
                 (scale-stream hammings 5)))))

(show-stream hammings 10)
1
2
3
4
5
6
8
9
10
12
done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s