3.14.2 Streams
A stream is a kind of sequence that supports functional iteration via stream-first and stream-rest. The stream-cons form constructs a lazy stream, but plain lists can be used as stream, and functions such as in-range and in-naturals also create streams.
procedure
(stream-empty? s) → boolean?
s : stream?
procedure
(stream-first s) → any
s : (and/c stream? (not/c stream-empty?))
procedure
(stream-rest s) → stream?
s : (and/c stream? (not/c stream-empty?))
syntax
(stream-cons first-expr rest-expr)
The first element of the stream as produced by first-expr must be a single value. The rest-expr must produce a stream when it is evaluated, otherwise the exn:fail:contract? exception is raised.
syntax
(stream expr ...)
value
procedure
(stream->list s) → list?
s : stream?
procedure
s : stream?
In the case of lazy streams, this function forces evaluation only of the sub-streams, and not the stream’s elements.
procedure
(stream-ref s i) → any
s : stream? i : exact-nonnegative-integer?
procedure
(stream-tail s i) → stream?
s : stream? i : exact-nonnegative-integer?
In case extracting elements from s involves a side effect, they will not be extracted until the first element is extracted from the resulting stream.
procedure
(stream-append s ...) → stream?
s : stream?
procedure
(stream-map f s) → stream?
f : procedure? s : stream?
procedure
f : procedure? s : stream?
procedure
(stream-add-between s e) → stream?
s : stream? e : any/c
value
To supply method implementations, the #:methods keyword should be used in a structure type definition. The following three methods should be implemented:
stream-empty? : accepts one argument
stream-first : accepts one argument
stream-rest : accepts one argument
Examples: | ||||||||||||||||||
|
value