Next: Weak References, Previous: Promises, Up: Miscellaneous Datatypes
In addition to promises, MIT/GNU Scheme supports a higher-level abstraction called streams. Streams are similar to lists, except that the tail of a stream is not computed until it is referred to. This allows streams to be used to represent infinitely long lists.
Returns a newly allocated stream whose elements are the arguments. Note that the expression
(stream)
returns the empty stream, or end-of-stream marker.
Returns a newly allocated stream whose elements are the elements of list. Equivalent to
(apply stream
list)
.
Returns a newly allocated list whose elements are the elements of stream. If stream has infinite length this procedure will not terminate. This could have been defined by
(define (stream->list stream) (if (stream-null? stream) '() (cons (stream-car stream) (stream->list (stream-cdr stream)))))
Returns a newly allocated stream pair. Equivalent to
(cons
object(delay
expression))
.
Returns
#t
if object is a pair whose cdr contains a promise. Otherwise returns#f
. This could have been defined by(define (stream-pair? object) (and (pair? object) (promise? (cdr object))))
Returns the first element in stream.
stream-car
is equivalent tocar
.stream-first
is a synonym forstream-car
.
Returns the first tail of stream. Equivalent to
(force (cdr
stream))
.stream-rest
is a synonym forstream-cdr
.
Returns
#t
if stream is the end-of-stream marker; otherwise returns#f
. This is equivalent tonull?
, but should be used whenever testing for the end of a stream.
Returns the number of elements in stream. If stream has an infinite number of elements this procedure will not terminate. Note that this procedure forces all of the promises that comprise stream.
Returns the element of stream that is indexed by k; that is, the kth element. K must be an exact non-negative integer strictly less than the length of stream.
Returns the first k elements of stream as a list. K must be an exact non-negative integer strictly less than the length of stream.