Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2a9dba2f9e
Fetching contributors…

Cannot retrieve contributors at this time

41 lines (30 sloc) 0.941 kb
#lang racket
(require racket/stream)
;; display
(define (display-stream-n stream n)
(if (<= n 0)
(display (stream-first stream))
(display-stream-n (stream-rest stream) (- n 1)))))
;; integers
(define (integers-starting-from n)
(stream-cons n (integers-starting-from (+ n 1))))
(define integers (integers-starting-from 1))
;; pairs i <= j
(define (interleave s1 s2)
(if (stream-empty? s1)
(stream-cons (stream-first s1)
(interleave s2 (stream-rest s1)))))
(define (pairs s t)
(list (stream-first s) (stream-first t)) ;; S0, T0
(stream-map (lambda (x) (list (stream-first s) ;; S0
x)) ;; S0, Ti
(stream-rest t))
(pairs (stream-rest s) (stream-rest t))))) ;; the same recursively
(define S (pairs integers integers))
(display-stream-n S 150)
Jump to Line
Something went wrong with that request. Please try again.