SICP Practice

Practice 3.69

(define (triples s t u)
  (cons-stream (list (stream-car s)
                     (stream-car t)
                     (stream-car u))
               (interleave (stream-map (lambda (x)
                                         (list (stream-car s)))
                                       (stream-cdr (pairs t u)))
                           (triples (stream-cdr s)
                                    (stream-cdr t)
                                    (stream-cdr u)))))

(define pythagoras-triple
  (stream-filter (lambda (x)
                   (let ((i (car x))
                         (j (cadr x))
                         (k (caddr x)))
                     (= (+ (square i) (square j)) (square k))))
                 (triples integers integers integers)))