1. Introduction
  2. Usage
  3. Documentation
    1. Primitive
      1. stream?
      2. stream-pair?
      3. stream-null?
      4. stream-null
      5. stream-cons
      6. stream-lambda
      7. stream-car
      8. stream-cdr
    2. Derived
      1. stream-of
      2. define-stream
      3. stream
      4. stream-let
      5. stream-match
      6. list->stream
      7. port->stream
      8. stream->list
      9. stream-append
      10. stream-concat
      11. stream-drop
      12. stream-drop-while
      13. stream-filter
      14. stream-fold
      15. stream-for-each
      16. stream-map
      17. stream-from
      18. stream-iterate
      19. stream-length
      20. stream-range
      21. stream-ref
      22. stream-reverse
      23. stream-scan
      24. stream-take
      25. stream-take-while
      26. stream-unfold
      27. stream-unfolds
      28. stream-zip
    3. Utilities
      1. stream-intersperse
      2. stream-permutations
      3. file->stream
      4. stream-split
      5. stream-unique
      6. stream-fold-one
      7. stream-member
      8. stream-merge
      9. stream-partition
      10. stream-finds
      11. stream-find
      12. stream-remove
      13. stream-every
      14. stream-any
      15. stream-and
      16. stream-or
      17. stream-fold-right
      18. stream-fold-right-one
      19. stream-assoc
      20. stream-equal?
      21. stream-quick-sort
      22. stream-insertion-sort
      23. stream-merge-sort
      24. stream-maximum
      25. stream-minimum
    4. Math Utilities
      1. stream-sum
      2. stream-max
      3. stream-min
      4. odd-numbers-stream
      5. even-numbers-stream
      6. natural-numbers-stream
      7. prime-numbers-stream
      8. hamming-sequence-stream
  4. Examples
  5. Author
  6. License
  7. Version history

Introduction

SRFI-41 for Chicken Scheme.

Usage

(require-extension srfi-41)

Documentation

See the SRFI-41 Document.

Primitive

stream?

[procedure] (stream? OBJECT)

stream-pair?

[procedure] (stream-pair? OBJECT)

stream-null?

[procedure] (stream-null? OBJECT)

stream-null

[stream] stream-null

stream-cons

[syntax] (stream-cons OBJECT STREAM)

stream-lambda

[syntax] (stream-lambda FORMALS BODY ...)

stream-car

[procedure] (stream-car STREAM)

stream-cdr

[procedure] (stream-cdr STREAM)

Derived

stream-of

[syntax] (stream-of EXPRESSION (VARIABLE in STREAM)/(VARIABLE is EXPRESSION)/PREDICATE ...)

define-stream

[syntax] (define-stream (NAME [FORMAL ...]) BODY ...)

stream

[syntax] (stream) stream-null)

stream-let

[syntax] (stream-let TAG ((NAME VALUE) ...) BODY ...)

stream-match

[syntax] (stream-match STREAM-EXPRESSION CLAUSE ...)

list->stream

[procedure] (list->stream LIST)

port->stream

[procedure] (port->stream [PORT (current-input-port)])

stream->list

[procedure] (stream->list [COUNT #f] STREAM)

stream-append

[procedure] (stream-append STREAM ...)

stream-concat

[procedure] (stream-concat STREAMS)

stream-drop

[procedure] (stream-drop N STREAM)

stream-drop-while

[procedure] (stream-drop-while PREDICATE STREAM)

stream-filter

[procedure] (stream-filter PREDICATE STREAM)

stream-fold

[procedure] (stream-fold PROCEDURE BASE STREAM)

stream-for-each

[procedure] (stream-for-each PROCEDURE STREAM ...)

stream-map

[procedure] (stream-map PROCEDURE STREAM ...)

stream-from

[procedure] (stream-from FIRST [STEP 1])

stream-iterate

[procedure] (stream-iterate PROCEDURE BASE)

stream-length

[procedure] (stream-length STREAM)

stream-range

[procedure] (stream-range FIRST PAST [STEP (if (< FIRST PAST) 1 -1)])

stream-ref

[procedure] (stream-ref STREAM INDEX)

stream-reverse

[procedure] (stream-reverse STREAM)

stream-scan

[procedure] (stream-scan PROCEDURE BASE STREAM)

stream-take

[procedure] (stream-take N STREAM)

stream-take-while

[procedure] (stream-take-while PREDICATE STREAM)

stream-unfold

[procedure] (stream-unfold MAPPER PREDICATE GENERATOR BASE)

stream-unfolds

[procedure] (stream-unfolds GENERATOR SEED)

stream-zip

[procedure] (stream-zip STREAM ...)

Utilities

(require-extension srfi-41-utils)

stream-intersperse

[stream] (stream-intersperse STREAM OBJECT)

stream-permutations

[stream] (stream-permutations STREAM)

file->stream

[stream] (file->stream FILENAME [READ-PROCEDURE read-char])

stream-split

[procedure] (stream-split N STREAM)

stream-unique

[stream] (stream-unique EQUIVALENCE STREAM)

stream-fold-one

[procedure] (stream-fold-one FUNCTION STREAM)

stream-member

[stream] (stream-member EQUIVALENCE OBJECT STREAM)

stream-merge

[stream] (stream-merge LESS-THAN STREAM ...)

stream-partition

[procedure] (stream-partition PREDICATE STREAM)

stream-finds

[stream] (stream-finds EQUIVALENCE OBJECT STREAM)

stream-find

[procedure] (stream-find EQUIVALENCE OBJECT STREAM)

stream-remove

[stream] (stream-remove PREDICATE STREAM)

stream-every

[procedure] (stream-every PREDICATE STREAM)

stream-any

[procedure] (stream-any PREDICATE STREAM)

stream-and

[procedure] (stream-and STREAM)

stream-or

[procedure] (stream-or STREAM)

stream-fold-right

[procedure] (stream-fold-right FUNCTION BASE STREAM)

stream-fold-right-one

[procedure] (stream-fold-right-one FUNCTION STREAM)

stream-assoc

[procedure] (stream-assoc KEY STREAM)

stream-equal?

[procedure] (stream-equal? EQUIVALENCE STREAM1 STREAM2)

stream-quick-sort

[stream] (stream-quick-sort LESS-THAN STREAM)

stream-insertion-sort

[stream] (stream-insertion-sort LESS-THAN STREAM)

stream-merge-sort

[stream] (stream-merge-sort LESS-THAN STREAM)

stream-maximum

[procedure] (stream-maximum LESS-THAN STREAM)

stream-minimum

[procedure] (stream-minimum LESS-THAN STREAM)

Math Utilities

(require-extension srfi-41-math)

stream-sum

[stream] stream-sum

stream-max

[procedure] (stream-max STREAM)

stream-min

[procedure] (stream-min STREAM)

odd-numbers-stream

[stream] odd-numbers-stream

even-numbers-stream

[stream] even-numbers-stream

natural-numbers-stream

[stream] natural-numbers-stream

prime-numbers-stream

[stream] prime-numbers-stream

hamming-sequence-stream

[stream] hamming-sequence-stream

Examples

(define (sigma FUNCTION m n)
  (stream-fold + 0 (stream-map FUNCTION (stream-range m (+ n 1)))))

(define (factorial n)
  (stream-ref (stream-scan * 1 (stream-from 1))) n)

(define odd-numbers-stream (stream-from 1 2))

(define even-numbers-stream (stream-from 0 2))

(define natural-numbers-stream (stream-iterate add1 0))

(define prime-numbers-stream
  (let ()
    (define-stream (next base mult STREAM)
      (let ((first (stream-car STREAM))
            (rest (stream-cdr STREAM)))
        (cond ((< first mult)
                (stream-cons first (next base mult rest)))
              ((< mult first)
                (next base (+ base mult) STREAM))
              (else (next base (+ base mult) rest)))))
    (define-stream (sift base STREAM)
      (next base (+ base base) STREAM))
    (define-stream (sieve STREAM)
      (let ((first (stream-car STREAM))
            (rest (stream-cdr STREAM)))
        (stream-cons first (sieve (sift first rest)))))
    (sieve (stream-from 2))))

;; http://www.research.att.com/~njas/sequences/A051037

(define hamming-sequence-stream
  (stream-cons 1
    (stream-unique =
      (stream-merge <
        (stream-map (left-section * 2) hamming-sequence-stream)
        (stream-map (left-section * 3) hamming-sequence-stream)
        (stream-map (left-section * 5) hamming-sequence-stream)))))

Author

Philip L. Bewig

Chicken Port: Kon Lovett

License

Copyright (C) 2007 by Philip L. Bewig of Saint Louis, Missouri, USA. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version history

1.0
Release