Describe the streams A and B produced by the following definitions. Assume that integers
is the stream of positive integers (starting from 1):
To get some initial practice with streams, write definitions for each of the following:
alt_ones
: the stream 1, -1, 1, -1, … in as many ways as you can think of.zeroes
: the infinite stream of 0's. Do this using alt_ones
in as many ways as you can think of.Now, show how to define the series:
Given a stream s
the following function returns a stream of pairs of elements from s
:
Suppose that ints
is the (finite) stream 1, 2, 3, 4, 5. What is stream_pairs(ints)
Give the clearest explanation you can of how stream_pairs
works.
Suppose that integers
is the infinite stream of positive integers. What is the result of evaluating
Hint: Note the function stream_append
is defined Source S3 as follows:
Consider the following variant of stream_append
, called stream_append_pickle
and the function stream_pairs2
which makes use of it.
Why does the function stream_pair2
solve the problem that arose in the previous question?
What are the first few elements of stream_pairs2(integers)
? Can you suggest a modification of stream_pairs2
that would be more appropriate in dealing with infinite streams?