Next: Blocking Mode, Previous: Input Port Operations, Up: Port Primitives
This section describes the standard operations on output ports. Following that, some useful custom operations are described.
Writes char to output-port and returns an unspecified value.
Writes the substring specified by string, start, and end to output-port and returns an unspecified value. Equivalent to writing the characters of the substring, one by one, to output-port, but is implemented very efficiently.
Most output ports are able to tell whether or not they are at the beginning of a line of output. If output-port is such a port, end-of-line is written to the port only if the port is not already at the beginning of a line. If output-port is not such a port, an end-of-line is unconditionally written to the port. Returns an unspecified value.
If output-port is buffered, this causes its buffer to be written out. Otherwise it has no effect. Returns an unspecified value.
Normally, this operation does nothing. However, ports that support discretionary output flushing implement this operation identically to
flush-output
.
Each of these procedures invokes the respective operation on output-port. For example, the following are equivalent:
(output-port/write-char output-port char) ((port/operation output-port 'write-char) output-port char)
Writes string to output-port. Equivalent to
(output-port/write-substring output-port string 0 (string-length string))
The following custom operations are generally useful.
Returns the number of unwritten characters that are stored in output-port's buffer. This will always be less than or equal to the buffer's size.
Returns the maximum number of characters that output-port's buffer can hold.
Resizes output-port's buffer so that it can hold at most size characters. Characters in the buffer are discarded. Size must be an exact non-negative integer.
Returns an exact positive integer that is the width of output-port in characters. If output-port has no natural width, e.g. if it is a file port,
#f
is returned.
Returns an exact positive integer that is the height of output-port in characters. If output-port has no natural height, e.g. if it is a file port,
#f
is returned.
This procedure invokes the custom operation whose name is the symbol
x-size
, if it exists. If thex-size
operation is both defined and returns a value other than#f
, that value is returned as the result of this procedure. Otherwise,output-port/x-size
returns a default value (currently80
).
output-port/x-size
is useful for programs that tailor their output to the width of the display (a fairly common practice). If the output device is not a display, such programs normally want some reasonable default width to work with, and this procedure provides exactly that.