1.1 KiB
Input and Output Ports
A port encapsulates an I/O stream, normally for just one direction. An input port reads from a stream, and an output port writes to a string.
For many procedures that accept a port argument, the argument is
optional, and it defaults to either the current input port or current
output port. For mzscheme
, the current ports are initialized to the
process’s stdin and stdout. The current-input-port
and
current-output-port
procedures, when called with no arguments, return
the current output and input port, respectively.
Examples:
> (display "hello world\n")
hello world
> (display "hello world\n" (current-output-port))
hello world
Ports are created by various procedures that specific to the different
kinds of streams. For example, open-input-file
creates an input port
for reading from a file. Procedures like with-input-from-file
both
create a port and install it as the current port while calling a given
body procedure.
See [missing] for information about using ports.