Next: , Previous: , Up: Input/Output   [Contents][Index]


14.12 Textual Port Primitives

This section describes the low-level operations that can be used to build and manipulate textual I/O ports. The purpose of these operations is to allow programmers to construct new kinds of textual I/O ports.

The mechanisms described in this section are exclusively for textual ports; binary ports can’t be customized. In this section, any reference to a “port” that isn’t modified by “textual” or “binary” is assumed to be a textual port.

The abstract model of a textual I/O port, as implemented here, is a combination of a set of named operations and a state. The state is an arbitrary object, the meaning of which is determined by the operations. The operations are defined by a mapping from names to procedures.

The set of named operations is represented by an object called a textual port type. A port type is constructed from a set of named operations, and is subsequently used to construct a port. The port type completely specifies the behavior of the port. Port types also support a simple form of inheritance, allowing you to create new ports that are similar to existing ports.

The port operations are divided into two classes:

Standard operations

There is a specific set of standard operations for input ports, and a different set for output ports. Applications can assume that the standard input operations are implemented for all input ports, and likewise the standard output operations are implemented for all output ports.

Custom operations

Some ports support additional operations. For example, ports that implement output to terminals (or windows) may define an operation named y-size that returns the height of the terminal in characters. Because only some ports will implement these operations, programs that use custom operations must test each port for their existence, and be prepared to deal with ports that do not implement them.


Next: Parser Buffers, Previous: Prompting, Up: Input/Output   [Contents][Index]