chickadee » srfi-41

srfi-41

SRFI 41 for Chicken Scheme.

Documentation

See the SRFI-41 Document.

Primitive

Usage

(require-extension streams-primitive)

stream?

(stream? OBJECT) => boolean procedure

stream-pair?

(stream-pair? OBJECT) => boolean procedure

stream-null?

(stream-null? OBJECT) => boolean procedure

stream-occupied?

(stream-occupied? OBJECT) => boolean procedure

Inverse of stream-null?.

stream-null

stream-null constant

The null stream value.

stream-cons

(stream-cons OBJECT STREAM) => stream syntax

stream-lambda

(stream-lambda FORMALS BODY ...) => procedure syntax

stream-car

(stream-car STREAM) => * procedure

stream-cdr

(stream-cdr STREAM) => stream procedure

Derived

Usage

(require-extension streams-derived)

define-stream

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

stream-of

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

stream-let

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

stream-match

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

stream

(stream OBJECT...) => stream syntax

list->stream

(list->stream LIST) => stream procedure

port->stream

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

stream->list

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

stream-append

(stream-append STREAM...) => stream procedure

stream-concat

(stream-concat STREAM) => stream procedure

Flatten a stream of streams.

stream-drop

(stream-drop COUNT STREAM) => stream procedure

stream-drop-while

(stream-drop-while PREDICATE STREAM) => stream procedure

stream-filter

(stream-filter PREDICATE STREAM) => stream procedure

stream-fold

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

stream-for-each

(stream-for-each FUNCTION STREAM...) => stream procedure

stream-map

(stream-map FUNCTION STREAM...) => stream procedure

stream-from

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

stream-iterate

(stream-iterate FUNCTION BASE) => stream procedure

stream-length

(stream-length STREAM) => FIXNUM procedure

stream-range

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

stream-ref

(stream-ref STREAM INDEX) => * procedure

stream-reverse

(stream-reverse STREAM) => stream procedure

stream-scan

(stream-scan FUNCTION BASE STREAM) => stream procedure

stream-unfold

(stream-unfold MAPPER PREDICATE GENERATOR BASE) => stream procedure

stream-unfolds

(stream-unfolds GENERATOR SEED) => stream procedure

stream-zip

(stream-zip STREAM...) => stream procedure

Utilities

Usage

(require-extension streams-utils)

stream-intersperse

(stream-intersperse STREAM OBJECT) => stream procedure

stream-permutations

(stream-permutations STREAM) => stream procedure

file->stream

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

stream-split

(stream-split COUNT STREAM) => (values STREAM STREAM) procedure

stream-unique

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

stream-fold-one

(stream-fold-one FUNCTION STREAM) => stream procedure

stream-member

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

stream-merge

(stream-merge <? STREAM ...) => stream procedure

stream-partition

(stream-partition PREDICATE STREAM) => stream procedure

stream-finds

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

stream-find

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

stream-remove

(stream-remove PREDICATE STREAM) => stream procedure

stream-every

(stream-every PREDICATE STREAM) => boolean procedure

stream-any

(stream-any PREDICATE STREAM) => boolean procedure

stream-and

(stream-and STREAM) => boolean procedure

stream-or

(stream-or STREAM) => boolean procedure

stream-fold-right

(stream-fold-right FUNCTION BASE STREAM) => * procedure

stream-fold-right-one

(stream-fold-right-one FUNCTION STREAM) => * procedure

stream-assoc

(stream-assoc KEY STREAM [=? equal?]) => * procedure

stream-equal?

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

stream-quick-sort

(stream-quick-sort <? STREAM) => stream procedure

stream-insertion-sort

(stream-insertion-sort <? STREAM) => stream procedure

stream-merge-sort

(stream-merge-sort <? STREAM) => stream procedure

stream-maximum

(stream-maximum <? STREAM) => * procedure

stream-minimum

(stream-minimum <? STREAM) => * procedure

binary-tree-same-fringe?

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

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

Lazy version of the same fringe.

Math Utilities

Usage

(require-extension streams-math)

stream-max

(stream-max STREAM) => * procedure

stream-min

(stream-min STREAM) => * procedure

stream-sum

stream-sum constant

odd-numbers-stream

odd-numbers-stream constant

even-numbers-stream

even-numbers-stream constant

cardinal-numbers-stream

cardinal-numbers-stream constant

natural-numbers-stream

natural-numbers-stream constant

prime-numbers-stream

prime-numbers-stream constant

hamming-sequence-stream

hamming-sequence-stream constant

Examples

(use streams)

(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))

Usage

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

(require-extension streams)
 Or (a synonym)
(require-extension srfi-41)

Requirements

check-errors combinators record-variants

Author

Philip L. Bewig

Kon Lovett

Version history

1.2.2
Check for stream type when forcing; reported by Jim Ursetto. Faster prime number stream; thanks to Matthias Bauer.
1.2.1
1.2.0
Use of record-variants & combinators.
1.1.0
Added "srfi-41" modules as synonynom of "streams".
1.0.2
Bug fix for problem w/ use of 'obj' in "streams-utils" reported by Josh Griffith. Better error message for nary stream procedures.
1.0.1
Updated test.
1.0.0
Chicken 4 release.

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 "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.

Copyright (C) 2009 Kon Lovett. 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.

Contents »