This section describes the protocol for positionable streams.
A stream position can be thought of as a natural number that indicates how many elements into the stream the stream's current location is. However, it is not always the case that a single integer contains enough information to reposition a stream. Consider the case of an "uncompressing" file stream that requires additional state beyond simply the file position to be able to get the next input character from the compressed file.
The Streams module addresses this problem by introducing the class <stream-position>, which is subclassed by various kinds of stream implementations that need to maintain additional state. A stream can be repositioned as efficiently as possible when stream-position-setter is given a value previously returned by stream-position on that stream.
It is also legal to set the position of a stream to an integer position. However, for some types of streams, to do so might be slow, perhaps requiring the entire contents of the stream up to that point to be read.
<position-type>Type
type-union(<stream-position>, <integer>)
<integer>, but this type, together with the <stream-position> class, allows for cases where this might not be possible.
Abstract class
<object>. It is used in rare cases to represent positions within streams that cannot be represented as instances of <integer>, such as a stream that supports compression.
Open generic function
stream-position positionable-stream => position
Open generic function
stream-position-setter position positionable-stream => new-position
.stream-size, a valid <stream-position>, #"start", or #"end".
stream-position-setter to set the position past the current last element of the stream: use adjust-stream-position instead.
Open generic function
adjust-stream-position positionable-stream delta #key from => new-position
<integer>.
#"current", #"start", and #"end". The default is #"current".
adjust-stream-position to set the position of a stream to be beyond its current last element grows the underlying aggregate to a new size.
G.f. method
as integer-class stream-position => integer
<stream-position> to an integer. The integer-class argument is the class <integer>.
Open generic function
stream-size positionable-stream => size
Open generic function
stream-contents positionable-stream #key clear-contents? => sequence
read. See page 44.
#t (the default for streams to which it is applicable), this function sets the size of the stream to zero, and the position to the stream's start. Thus the next call to stream-contents will return only the elements written after the previous call to stream-contents. The clear-contents? argument is not defined for file streams, or any other external stream. It is also an error to apply it to input-only streams.
read-to-end for input streams.
Open generic function
unread-element positionable-stream element => element
read-element returns element. It is an error if element was not the last element read from the stream. You may not call unread-element more than once without an intervening read operation (that is, you cannot unread more than one element at a time).