chickadee » sicp » pairs

pairs s tprocedure

Generates the stream of pairs (S_i, T_j), where i <= j.

s
The first stream to pair
t
The second stream to pair
(define (pairs s t)
  (cons-stream
    (list (stream-car s) (stream-car t))
    (interleave
      (stream-map (lambda (x) (list (stream-car s) x)) (stream-cdr t))
      (pairs (stream-cdr s) (stream-cdr t)))))