scheme@(guile-user)> (define output (Heaps-stream (list->stream input))) scheme@(guile-user)> (stream-for-each (lambda (s) (display (stream->list s)) (newline)) (stream-take (* 1 2 3 4 5 6 7) output)) (a b c d e f g) (b a c d e f g) (c a b d e f g) (a c b d e f g) (b c a d e f g) (c b a d e f g) (d b a c e f g) (b d a c e f g) (a d b c e f g) (d a b c e f g) (b a d c e f g) (a b d c e f g) (a c d b e f g) (c a d b e f g) (d a c b e f g) (a d c b e f g) (c d a b e f g) (d c a b e f g) ... (c g b d e f a) (b g c d e f a) (g b c d e f a) scheme@(guile-user)> (define n (stream-from 0)) ; a stream of natural numbers from 0 scheme@(guile-user)> (define s (Heaps-stream n)) scheme@(guile-user)> (stream->list (stream-take 10 (stream-ref s 0))) \$1 = (0 1 2 3 4 5 6 7 8 9) scheme@(guile-user)> (stream->list (stream-take 10 (stream-ref s 1))) \$2 = (1 0 2 3 4 5 6 7 8 9) scheme@(guile-user)> (stream->list (stream-take 10 (stream-ref s 2))) \$3 = (2 0 1 3 4 5 6 7 8 9) scheme@(guile-user)> (stream->list (stream-take 10 (stream-ref s 100))) \$4 = (4 1 3 2 0 5 6 7 8 9) scheme@(guile-user)> (stream->list (stream-take 10 (stream-ref s 1000))) \$5 = (2 6 0 1 5 4 3 7 8 9) scheme@(guile-user)> (stream->list (stream-take 10 (stream-ref s 10000))) \$6 = (3 4 0 2 1 5 7 6 8 9) scheme@(guile-user)> (stream->list (stream-take 10 (stream-ref s 100000))) \$7 = (5 0 8 1 7 2 3 6 4 9) scheme@(guile-user)>