Next Previous Up Top Contents Index

5.11 The STREAMS module

write

Open generic function

Summary

Writes the elements of a sequence to an output stream.

Signature

write output-stream sequence #key start end => () 

Arguments

output-stream
An instance of <stream>.

sequence
An instance of <sequence>.

start
An instance of <integer>. Default value: 0.

end
An instance of <integer>. Default value: sequence.size.

Values

None.

Library

io

Module

streams

Description

Writes the elements of sequence to output-stream, starting at the stream's current position.

The elements in sequence are accessed in the order defined by the forward iteration protocol on <sequence>. This is effectively the same as the following:

do (method (elt) write-element(stream, elt) 
    end, sequence); 
sequence;

If supplied, start and end delimit the portion of sequence to write to the stream. The value of start is inclusive and that of end is exclusive.

If the stream is positionable, and it is not positioned at its end, write overwrites elements in the stream and then advance the stream's position to be beyond the last element written.

Implementation Note: Buffered streams are intended to provide a very efficient implementation of write, particularly when sequence is an instance of <byte-string>, <unicode-string>, <byte-vector>, or <buffer>, and the stream's element type is the same as the element type of sequence.

Example

The following forms bind stream to an output stream over an empty string and create the string "I see!", using the function stream-contents to access all of the stream's elements.

let stream = make(<byte-string-stream>, 
                  direction: #"output");
write-element(stream, 'I');
write-element(stream, ' ');
write(stream, "see");
write-element(stream, '!');
stream-contents(stream);

See also

read, page 44

write-element, page 112

write-line, page 113


System and I/O Reference - 31 MAR 2000

Next Previous Up Top Contents Index