Use the same logic as the table diagram in the book: the stream now consists of *four* parts, not three, the upper-left corner, the top row, a new "left column", and the lower-right block

(define(all-pairs s t)(cons-stream
(list(stream-car s)(stream-car t));; upper-left corner
(interleave
(interleave
(stream-map (lambda(x)(list(stream-car s) x))(stream-cdr t));; top row
(stream-map (lambda(x)(list x (stream-car t)))(stream-cdr s)));; left column
(all-pairs (stream-cdr s)(stream-cdr t)))));; lower-right block
(define(partial-stream->list stream n)(define(rec str i)(if(= i n)()(cons(stream-car str)(rec (stream-cdr str)(1+ i)))))(rec stream 0));; utility function to return list of first n items
(partial-stream->list (all-pairs integers integers) 10);; ((1 1) (1 2) (2 2) (2 1) (2 3) (1 3) (3 3) (3 1) (3 2) (1 4))

I'm also curious to know, I don't see any reason to make it so complicated. The start of the stream is (1,1), after that an interleaving of (1,x) and ((2,1) and interleaving of (2,x) and ((3,1) and interleaving of (3,x) etc ...

The table can still be divided into 3 parts:

genovia

meteorgan

mart256

@genovia I took a look at your answer and I think it would repeat pairs, I found the pair (1,3) repeated at least.

Here's my solution, I think it should work, it is similar to @meteorgan answer.

xdavidliu

Use the same logic as the table diagram in the book: the stream now consists of *four* parts, not three, the upper-left corner, the top row, a new "left column", and the lower-right block

yasser

My answer is similar to 3pmtea's answer. What do you guys think of it?

master

I'm also curious to know, I don't see any reason to make it so complicated. The start of the stream is

(1,1), after that an interleaving of(1,x)and ((2,1)and interleaving of(2,x)and ((3,1)and interleaving of(3,x)etc ...Won't such a stream contain all pairs?

krubar

Just by examining output of solution given by 3pmtea, it looks correct.