srfi-41

SRFI 41 for Chicken Scheme.

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

Documentation

See the SRFI-41 Document.

Usage

The exports of streams-primitive and streams-derived are povided by:

(import srfi-41)
  ;Or (a synonym)
(import streams)

Primitive

Usage

(import (streams primitive))

stream?

[procedure] (stream? OBJECT) -> boolean

stream-pair?

[procedure] (stream-pair? OBJECT) -> boolean

stream-null?

[procedure] (stream-null? OBJECT) -> boolean

stream-occupied?

[procedure] (stream-occupied? OBJECT) -> boolean

Inverse of stream-null?.

stream-null

[constant] stream-null

The null stream value.

stream-cons

[syntax] (stream-cons OBJECT STREAM) -> stream

stream-lambda

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

stream-car

[procedure] (stream-car STREAM) -> *

stream-cdr

[procedure] (stream-cdr STREAM) -> stream

Derived

Usage

(import (streams derived))

define-stream

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

stream-of

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

stream-let

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

stream-match

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

stream

[syntax] (stream OBJECT...) -> stream

list->stream

[procedure] (list->stream LIST) -> stream

port->stream

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

stream->list

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

stream-append

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

stream-concat

[procedure] (stream-concat STREAM) -> stream

Flatten a stream of streams.

stream-drop

[procedure] (stream-drop COUNT STREAM) -> stream

stream-drop-while

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

stream-filter

[procedure] (stream-filter PREDICATE STREAM) -> stream

stream-fold

[procedure] (stream-fold FUNCTION BASE STREAM...) -> *

stream-for-each

[procedure] (stream-for-each FUNCTION STREAM...) -> stream

stream-map

[procedure] (stream-map FUNCTION STREAM...) -> stream

stream-from

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

stream-iterate

[procedure] (stream-iterate FUNCTION BASE) -> stream

stream-length

[procedure] (stream-length STREAM) -> FIXNUM

stream-range

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

stream-ref

[procedure] (stream-ref STREAM INDEX) -> *

stream-reverse

[procedure] (stream-reverse STREAM) -> stream

stream-scan

[procedure] (stream-scan FUNCTION BASE STREAM) -> stream

stream-unfold

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

stream-unfolds

[procedure] (stream-unfolds GENERATOR SEED) -> stream

stream-zip

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

Utilities

Usage

(import (streams utils))

stream-intersperse

[procedure] (stream-intersperse STREAM OBJECT) -> stream

stream-permutations

[procedure] (stream-permutations STREAM) -> stream

file->stream

[procedure] (file->stream FILENAME [READER read-char]) -> stream

stream-split

[procedure] (stream-split COUNT STREAM) -> (values STREAM STREAM)

stream-unique

[procedure] (stream-unique =? STREAM) -> stream

stream-fold-one

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

stream-member

[procedure] (stream-member =? OBJECT STREAM) -> stream

stream-merge

[procedure] (stream-merge <? STREAM ...) -> stream

stream-partition

[procedure] (stream-partition PREDICATE STREAM) -> stream

stream-finds

[procedure] (stream-finds =? OBJECT STREAM) -> stream

stream-find

[procedure] (stream-find =? OBJECT STREAM) -> stream

stream-remove

[procedure] (stream-remove PREDICATE STREAM) -> stream

stream-every

[procedure] (stream-every PREDICATE STREAM) -> boolean

stream-any

[procedure] (stream-any PREDICATE STREAM) -> boolean

stream-and

[procedure] (stream-and STREAM) -> boolean

stream-or

[procedure] (stream-or STREAM) -> boolean

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 [=? equal?]) -> *

stream-equal?

[procedure] (stream-equal? =? STREAM1 STREAM2) -> boolean

stream-quick-sort

[procedure] (stream-quick-sort <? STREAM) -> stream

stream-insertion-sort

[procedure] (stream-insertion-sort <? STREAM) -> stream

stream-merge-sort

[procedure] (stream-merge-sort <? STREAM) -> stream

stream-maximum

[procedure] (stream-maximum <? STREAM) -> *

stream-minimum

[procedure] (stream-minimum <? STREAM) -> *

binary-tree-same-fringe?

[procedure] (binary-tree-same-fringe? TREE1 TREE2) -> boolean

TREE1 and TREE2 are binary-tree nodes, so either () or pair.

Lazy version of the same fringe.

Math Utilities

Usage

(import (streams math))

stream-max

[procedure] (stream-max STREAM) -> *

stream-min

[procedure] (stream-min STREAM) -> *

stream-sum

[constant] stream-sum

odd-numbers-stream

[constant] odd-numbers-stream

even-numbers-stream

[constant] even-numbers-stream

cardinal-numbers-stream

[constant] cardinal-numbers-stream

natural-numbers-stream

[constant] natural-numbers-stream

prime-numbers-stream

[constant] prime-numbers-stream

hamming-sequence-stream

[constant] hamming-sequence-stream

Examples

(import srfi-41)

(define (sigma function m n)
  (stream-fold + 0 (stream-map function (stream-range m (add1 n)))))

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

Requirements

check-errors record-variants

test-utils

Author

Philip L. Bewig

Kon Lovett

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/srfi-41

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

Version history

2.1.5
Apply Chris Jester-Young's 2015 stream-constant speedup.
2.1.4
Add multiple value result for stream-match.
2.1.3
.
2.1.2
.
2.1.1
.
2.1.0
Add (streams derived) style module naming.
2.0.4
.
2.0.0
CHICKEN 5 release.

License

Copyright (C) 2023 Kon Lovett. Copyright (C) 2007 by Philip L. Bewig of Saint Louis, Missouri, USA.

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 "AS IS", 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.