(r5rs.info.gz) Ports
Info Catalog
(r5rs.info.gz) Input and output
(r5rs.info.gz) Input and output
(r5rs.info.gz) Input
6.6.1 Ports
-----------
Ports represent input and output devices. To Scheme, an input port is a
Scheme object that can deliver characters upon command, while an output
port is a Scheme object that can accept characters.
-- library procedure: call-with-input-file string proc
-- library procedure: call-with-output-file string proc
STRING should be a string naming a file, and PROC should be a
procedure that accepts one argument. For `call-with-input-file',
the file should already exist; for `call-with-output-file', the
effect is unspecified if the file already exists. These procedures
call PROC with one argument: the port obtained by opening the
named file for input or output. If the file cannot be opened, an
error is signalled. If PROC returns, then the port is closed
automatically and the value(s) yielded by the PROC is(are)
returned. If PROC does not return, then the port will not be
closed automatically unless it is possible to prove that the port
will never again be used for a read or write operation.
_Rationale:_ Because Scheme's escape procedures have
unlimited extent, it is possible to escape from the current
continuation but later to escape back in. If implementations
were permitted to close the port on any escape from the
current continuation, then it would be impossible to write
portable code using both `call-with-current-continuation' and
`call-with-input-file' or `call-with-output-file'.
-- procedure: input-port? obj
-- procedure: output-port? obj
Returns #t if OBJ is an input port or output port respectively,
otherwise returns #f.
-- procedure: current-input-port
-- procedure: current-output-port
Returns the current default input or output port.
-- optional procedure: with-input-from-file string thunk
-- optional procedure: with-output-to-file string thunk
STRING should be a string naming a file, and PROC should be a
procedure of no arguments. For `with-input-from-file', the file
should already exist; for `with-output-to-file', the effect is
unspecified if the file already exists. The file is opened for
input or output, an input or output port connected to it is made
the default value returned by `current-input-port' or
`current-output-port' (and is used by (read), (write OBJ), and so
forth), and the THUNK is called with no arguments. When the THUNK
returns, the port is closed and the previous default is restored.
`With-input-from-file' and `with-output-to-file' return(s) the
value(s) yielded by THUNK. If an escape procedure is used to
escape from the continuation of these procedures, their behavior
is implementation dependent.
-- procedure: open-input-file filename
Takes a string naming an existing file and returns an input port
capable of delivering characters from the file. If the file
cannot be opened, an error is signalled.
-- procedure: open-output-file filename
Takes a string naming an output file to be created and returns an
output port capable of writing characters to a new file by that
name. If the file cannot be opened, an error is signalled. If a
file with the given name already exists, the effect is unspecified.
-- procedure: close-input-port port
-- procedure: close-output-port port
Closes the file associated with PORT, rendering the PORT incapable
of delivering or accepting characters.
These routines have no effect if the file has already been closed.
The value returned is unspecified.
Info Catalog
(r5rs.info.gz) Input and output
(r5rs.info.gz) Input and output
(r5rs.info.gz) Input
automatically generated byinfo2html