Previous: Channels, Up: I/O system


4.5.5 Channel ports

Built-in to Scheme48 are ports made atop channels. These are what are created by R5RS's standard file operations. The following names are exported by the channel-ports structure.

— procedure: call-with-input-file filename receiver –> values
— procedure: call-with-output-file filename receiver –> values
— procedure: with-input-from-file filename thunk –> values
— procedure: with-output-to-file filename thunk –> values
— procedure: open-input-file filename –> input-port
— procedure: open-output-file filename –> output-port

Standard R5RS file I/O operations. (These are also exported by the scheme structure.) The call-with-...put-file operations open the specified type of port and apply receiver to it; after receiver returns normally (i.e. nothing is done if there is a throw out of receiver), they close the port and return the values that receiver returned. With-input-from-file & with-output-to-file do similarly, but, rather than applying thunk to the port, they dynamically bind the current input & output ports, respectively, to the newly opened ports. Call-with-input-file, call-with-output-file, with-input-from-file, and with-output-to-file return the values that thunk returns. Open-input-file & open-output-file just open input & output ports; users of these operations must close them manually.

— procedure: input-channel->port channel [buffer-size] –> port
— procedure: output-channel->port channel [buffer-size] –> port

These create input & output ports atop the given channels and optional buffer sizes. The default buffer size is 4096 bytes.

— procedure: input-channel+closer->port channel closer [buffer-size] –> port
— procedure: output-channel+closer->port channel closer [buffer-size] –> port

Similarly, these create input & output ports atop the given channels and optional buffer sizes, but they allow for extra cleanup when the resulting ports are closed.

— procedure: port->channel port –> channel or #f

If port is a port created by the system's channel ports facility, port->channel returns the channel it was created atop; otherwise port->channel returns #f.

— procedure: force-channel-output-ports! –> unspecified

This attempts to force as much output as possible from all of the ports based on channels. This is used by Scheme48's POSIX libraries before forking the current process.