Previous: , Up: stdlib io   [Index]


5.8.3 Simple input/output

This section describes the (rnrs io simple (6)) library, which provides a somewhat more convenient interface for performing textual I/O on ports. This library implements most of the I/O procedures of the previous revision of this report.

The ports created by the procedures of this library are textual ports associated implementation–dependent transcoders.

Procedure: eof-object
Procedure: eof-object? obj

These are the same as eof-object and eof-object? from the (rnrs io ports (6)) library.

Procedure: call-with-input-file filename proc
Procedure: call-with-output-file filename proc

proc should accept one argument.

These procedures open the file named by filename for input or for output, with no specified file options, and call proc with the obtained port as an argument.

If proc returns, the port is closed automatically and the values returned by proc are returned.

If proc does not return, the port is not closed automatically, unless it is possible to prove that the port will never again be used for an I/O operation.

Procedure: input-port? obj
Procedure: output-port? obj

These are the same as the input-port? and output-port? procedures in the (rnrs io ports (6)) library.

Procedure: current-input-port
Procedure: current-output-port
Procedure: current-error-port

These are the same as the current-input-port, current-output-port, and current-error-port procedures from the (rnrs io ports (6)) library.

Procedure: with-input-from-file filename thunk
Procedure: with-output-to-file filename thunk

thunk must be a procedure and must accept zero arguments.

The file is opened for input or output using empty file options, and thunk is called with no arguments.

During the dynamic extent of the call to thunk, the obtained port is made the value returned by current-input-port or current-output-port procedures; the previous default values are reinstated when the dynamic extent is exited.

When thunk returns, the port is closed automatically. The values returned by thunk are returned.

If an escape procedure is used to escape back into the call to thunk after thunk is returned, the behavior is unspecified.

Procedure: open-input-file filename

Open filename for input, with empty file options, and return the obtained port.

Procedure: open-output-file filename

Open filename for output, with empty file options, and return the obtained port.

Procedure: close-input-port input-port
Procedure: close-output-port output-port

Close input-port or output-port, respectively.

Procedure: read-char
Procedure: read-char textual-input-port

Reads from textual-input-port, blocking as necessary until a character is available, or the data that is available cannot be the prefix of any valid encoding, or an end of file is reached.

If a complete character is available before the next end of file: read-char returns that character and updates the input port to point past that character.

If an end of file is reached before any data are read: read-char returns the end–of–file object.

If textual-input-port is omitted, it defaults to the value returned by current-input-port.

Procedure: peek-char
Procedure: peek-char textual-input-port

This is the same as read-char, but does not consume any data from the port.

Procedure: read
Procedure: read textual-input-port

Read an external representation from textual-input-port and return the datum it represents.

The read procedure operates in the same way as get-datum.

If textual-input-port is omitted, it defaults to the value returned by current-input-port.

Procedure: write-char char
Procedure: write-char char textual-output-port

Write an encoding of the character char to the textual-output-port, and return unspecified values.

If textual-output-port is omitted, it defaults to the value returned by current-output-port.

Procedure: newline
Procedure: newline textual-output-port

This is equivalent to using write-char to write #\linefeed to textual-output-port.

If textual-output-port is omitted, it defaults to the value returned by current-output-port.

Procedure: display obj
Procedure: display obj textual-output-port

Write a representation of obj to the given textual-output-port.

Strings that appear in the written representation are not enclosed in doublequotes, and no characters are escaped within those strings.

Character objects appear in the representation as if written by write-char instead of by write.

The display procedure returns unspecified values.

The textual-output-port argument may be omitted, in which case it defaults to the value returned by current-output-port.

Procedure: write obj
Procedure: write obj textual-output-port

Write the external representation of obj to textual-output-port.

The write procedure operates in the same way as put-datum.

If textual-output-port is omitted, it defaults to the value returned by current-output-port.


Previous: , Up: stdlib io   [Index]