A stream is a lazy sequence of values. Streams are implemented in soundscrape as pairs, where the car is the first value in the stream, and the cdr contains a promise to produce more of the stream. A stream ends with the empty list, and should be accessed via stream-car and stream-cdr. Streams should be created via stream-cons.
List streams all have the prototype (stream:type repeat-count . args). repeat-count is interpreted differently by different kinds of streams. In all cases, the elements of args may be either scalar values or other streams. In the case that the element is a stream, the stream will be allowed to run until its end.
This implementation is inspired by Abelson and Sussman's version in Structure and Interpretation of Computer Programs.
stream-cons CAR CDR | [Special Form] |
Cons together a stream, delaying evaluation of the expression given as CDR.
list->stream l | [Function] |
Make a stream out of a list.
stream->closure stream | [Function] |
[undocumented]
stream->list stream . n | [Function] |
Convert a stream to a list. An optional second argument n limits the size of the list.
stream-car stream | [Function] |
Access the car of stream.
stream-cdr stream | [Function] |
Access the cdr of stream, forcing the delayed evaluation.
stream-filter pass? stream | [Function] |
Selects from stream only those elements that satisfy the predicate pass?.
stream-flatten stream | [Function] |
Returns a stream that that will return all elements of stream, recursing into any contained streams. For example,
(stream->list (stream-flatten (list->stream (list 1 2 (list->stream (list 3 4 5)) 6 7)))) ⇒ (1 2 3 4 5 6 7)
stream-map func . args | [Function] |
Returns a stream of func called on the elements of the streams in args.
stream-null? stream | [Function] |
Returns #t if stream is finished.
stream-ref stream n | [Function] |
[undocumented]
stream-remove deny? stream | [Function] |
Removes from stream those elements that satisfy the predicate deny?.
stream:chooser repeat-count . l | [Function] |
Make a stream that chooses random elements from args. The stream will finish after returning repeat-count items, and stream-flatten is called on the result.
stream:geom start factor length | [Function] |
A geometric series starting at start, with a factor of factor, and with length length.
stream:iota len | [Function] |
A stream of the integers 0 to len, inclusive.
stream:sequence repeat-count . l | [Function] |
Make a stream that returns l in order. The sequence will repeat repeat-count times, and stream-flatten is called on the result.
stream:series start step length | [Function] |
An arithmetic series starting at start, incrementing by step, and with length length.
stream:shuffled-sequence repeat-count . l | [Function] |
Same as stream:sequence, but args are shuffled beforehand.
stream:xchooser repeat-count . l | [Function] |
Same as chooser, but will not return the same element twice in a row.
stream? stream | [Function] |
A predicate for streams. Only checks the first pair, however.