Next Previous Up Top Contents Index

5.6 Reading from and writing to streams

5.6.4 Reading and writing by lines

The following functions provide line-based input and output operations.

The newline sequence for string streams is a sequence comprising the single newline character \n. For character file streams, the newline sequence is whatever sequence of characters the underlying platform uses to represent a newline. For example, on MS-DOS platforms, the sequence comprises two characters: a carriage return followed by a linefeed.

Note: No other functions in the Streams module do anything to manage the encoding of newlines; calling write-element on the character \n does not cause the \n character to be written as the native newline sequence, unless \n happens to be the native newline sequence.

read-line

Open generic function

read-line input-stream #key on-end-of-stream => string-or-eof newline? 

Returns a newly allocated <string> containing all the input in input-stream up to the next newline. The string does not contain the newline itself.
newline? is #t if the read terminated with a newline or #f if the read terminated because it came to the end of the stream.
The type of the result string is chosen so that the string can contain characters of input-stream's element type. For example, if the element type is <byte-character>, the string will be a <byte-string>.
write-line

Open generic function

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

Writes string followed by a newline sequence to output-stream.
The default method behaves as though it calls write on string and then calls new-line, with output-stream locked across both calls.
If supplied, start and end delimit the portion of string to write to the stream. They default to 0 and string.size respectively.
new-line

Open generic function

new-line output-stream => ()

Writes a newline sequence to output-stream.
A method for new-line is defined on <string-stream> that writes the character \n to the string stream.

See also read-line-into!, page 87.


System and I/O Reference - 31 MAR 2000

Next Previous Up Top Contents Index