Next: Default Ports for Input, Output and Errors, Previous: Random Access, Up: Input and Output [Contents][Index]
The delimited-I/O module can be accessed with:
(use-modules (ice-9 rdelim))
It can be used to read or write lines of text, or read text delimited by a specified set of characters.
Return a line of text from port if specified, otherwise from the
value returned by (current-input-port). Under Unix, a line of text
is terminated by the first end-of-line character or by end-of-file.
If handle-delim is specified, it should be one of the following symbols:
trimDiscard the terminating delimiter. This is the default, but it will be impossible to tell whether the read terminated with a delimiter or end-of-file.
concatAppend the terminating delimiter (if any) to the returned string.
peekPush the terminating delimiter (if any) back on to the port.
splitReturn a pair containing the string read from the port and the terminating delimiter or end-of-file object.
Read a line of text into the supplied string buf and return the
number of characters added to buf. If buf is filled, then
#f is returned. Read from port if specified, otherwise
from the value returned by (current-input-port).
Read text until one of the characters in the string delims is
found or end-of-file is reached. Read from port if supplied,
otherwise from the value returned by (current-input-port).
handle-delim takes the same values as described for
read-line.
Read text into the supplied string buf.
If a delimiter was found, return the number of characters written,
except if handle-delim is split, in which case the return
value is a pair, as noted above.
As a special case, if port was already at end-of-stream, the EOF
object is returned. Also, if no characters were written because the
buffer was full, #f is returned.
It’s something of a wacky interface, to be honest.
Read characters from port into str until one of the
characters in the delims string is encountered. If
gobble is true, discard the delimiter character;
otherwise, leave it in the input stream for the next read. If
port is not specified, use the value of
(current-input-port). If start or end are
specified, store data only into the substring of str
bounded by start and end (which default to the
beginning and end of the string, respectively).
Return a pair consisting of the delimiter that terminated the
string and the number of characters read. If reading stopped
at the end of file, the delimiter returned is the
eof-object; if the string was filled without encountering
a delimiter, this value is #f.
Read a newline-terminated line from port, allocating storage as
necessary. The newline terminator (if any) is removed from the string,
and a pair consisting of the line and its delimiter is returned. The
delimiter may be either a newline or the eof-object; if
%read-line is called at the end of file, it returns the pair
(#<eof> . #<eof>).
Display obj and a newline character to port. If
port is not specified, (current-output-port) is
used. This procedure is equivalent to:
(display obj [port]) (newline [port])
For every unit provided by (rdelim-proc port), provide
this unit(rdelim) to proc to be processed. This will continue throughout
port until stop-pred returns #t.
stop-pred is eof-object? by default.
rdelim-proc has to advance through port with every call made to it.
Call proc for every line delimited by delims from port.
Call proc for every line in file. file must be a filename string.
The line provided to proc is guaranteed to be a string.
Next: Default Ports for Input, Output and Errors, Previous: Random Access, Up: Input and Output [Contents][Index]