All Manuals > LispWorks® User Guide and Reference Manual > 46 The STREAM Package

stream-write-sequence Generic Function

Summary

Writes a subsequence of a sequence to a stream.

Package

stream

Signature

stream-write-sequence stream sequence start end => result

Method signatures

stream-write-sequence (stream t) (sequence t) (start t) (end t)

stream-write-sequence (stream stream) (sequence t) (start t) (end t)

stream-write-sequence (stream buffered-stream) (sequence t) (start t) (end t)

Arguments
stream
A stream.
sequence
A sequence.
start
An integer.
end
An integer.
Values
result
A sequence.
Description

The generic function stream-write-sequence is used by write-sequence to write a subsequence of sequence delimited by start and end to stream.

The method specializing stream on t just signals an error.

The method specializing stream on stream checks if the element type of stream (as returned by stream-element-type) is a subtype of character.

If the element type is a subtype of character, then if sequence is a string, stream-write-sequence calls stream-write-string with the arguments. Otherwise it iterates over the elements of sequence between start and end, calling stream-write-char on each element that is a character. An error is signaled if a non-character element is found.

If the element type is not a subtype of character, then stream-write-sequence iterates over the elements of sequence between start and end, calling stream-write-byte on each element that is an integer. An error is signaled if a non-integer element is found.

The method specializing stream on buffered-stream is optimized to be efficient and is reliant on the proper implementation of buffered-stream. See the documentation for buffered-stream for details.

Notes

The method for stream detects and signals some errors itself, but may still get errors in stream-write-byte, stream-write-char, or stream-write-string if sequence contains elements that are out of the range that these functions can deal with when called with stream.

The method for stream is not very efficient, and it forces the element type to be what stream-element-type returns. If you need more flexibility then you should write your own method specialized on your stream type, which can be also be made more efficient if it can make assumptions about sequence or stream.

Prior to LispWorks 8.0, there were also methods specialized on fundamental-character-output-stream and fundamental-binary-output-stream, which used stream-write-char and stream-write-byte respectively without checking the element type. These have been removed in LispWorks 8.0.

See also

fundamental-binary-output-stream
fundamental-character-output-stream
stream-read-sequence
stream-write-byte
stream-write-char


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:31:01