Question: Define a pure, recursive function stream - zip that takes two arguments, each of which is a stream, and produces a stream of pairs, where
Define a pure, recursive function streamzip that takes two arguments, each of which is a stream, and produces a stream of pairs, where the
n
th
pairs car is the
n
th
element of xs and the
n
th
pairs cdr is the
n
th
element of ys If xs and ys do not have the same length, then streamzip should return a stream that has as many elements as the shortest of xs and ys That is if streamzip runs out of items in either xs or ys it can stop producing pairs. The behavior of streamzip is undefined if either xs or ys is not a stream.
Note that streamzip is like zip from Homework but it operates on streams. Unlike zip, we cannot assume that the two streams have the same length. The streamzip function must also potentially handle infinite streamsthere is no guarantee that xs and ys are finite streams.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
