Port Types - MIT/GNU Scheme 7.7.91
Description: MIT/GNU Scheme 7.7.91

Next: Constructors and Accessors for Ports, Previous: Port Primitives, Up: Port Primitives

#### 14.9.1 Port Types

The procedures in this section provide means for constructing port types with standard and custom operations, and accessing their operations.

— procedure: make-port-type operations port-type

> Creates and returns a new port type. Operations must be a list; each element is a list of two elements, the name of the operation (a symbol) and the procedure that implements it. Port-type is either `#f` or a port type; if it is a port type, any operations implemented by port-type but not specified in operations will be implemented by the resulting port type.

> Operations need not contain definitions for all of the standard operations; the procedure will provide defaults for any standard operations that are not defined. At a minimum, the following operations must be defined: for input ports, `read-char` and `peek-char`; for output ports, either `write-char` or `write-substring`. I/O ports must supply the minimum operations for both input and output.

> If an operation in operations is defined to be `#f`, then the corresponding operation in port-type is not inherited.

> If `read-char` is defined in operations, then any standard input operations defined in port-type are ignored. Likewise, if `write-char` or `write-substring` is defined in operations, then any standard output operations defined in port-type are ignored. This feature allows overriding the standard operations without having to enumerate them.

— procedure: port-type? object
— procedure: input-port-type? object
— procedure: output-port-type? object
— procedure: i/o-port-type? object

> These predicates return `#t` if object is a port type, input-port type, output-port type, or I/O-port type, respectively. Otherwise, they return `#f`.

— procedure: port-type/operations port-type

> Returns a newly allocated list containing all of the operations implemented by port-type. Each element of the list is a list of two elements — the name and its associated operation.

— procedure: port-type/operation-names port-type

> Returns a newly allocated list whose elements are the names of the operations implemented by port-type.

— procedure: port-type/operation port-type symbol

> Returns the operation named symbol in port-type. If port-type has no such operation, returns `#f`.