Go to the previous, next section.
The procedures in this section provide means for constructing ports with custom operations, accessing their operations, and manipulating their internal state.
procedure+: make-input-port operations object
procedure+: make-output-port operations object
procedure+: make-i/o-port operations object
Operations must be a list; each element is a list of two elements, the name of the operation and the procedure that implements it. A new port is returned with the given operations and a state component of object.
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
, peek-char
,
and char-ready?
; for output ports, either write-char
or
write-substring
; I/O ports must supply the minimum
operations for both input and output.
procedure+: port/copy port object
Returns a new copy of port, identical to the original except that its state component is object. Port is not modified.
port/copy
is normally used to speed up creation of ports. This
is done by creating a template using one of the port constructors
make-input-port
, make-output-port
, or
make-i/o-port
, as appropriate; a dummy state component is
supplied for the template. Then port/copy
is used to make a copy
of the template, supplying the copy with the correct state. This is
useful because the port constructors are somewhat slow, as they must
parse the operations list, provide defaulting for missing
operations, etc.
For compatibility with old code, input-port/copy
and
output-port/copy
are synonyms for this procedure.
Returns the state component of port.
For compatibility with old code, input-port/state
and
output-port/state
are synonyms for this procedure.
procedure+: set-port/state! port object
Changes the state component of port to be object. Returns an unspecified value.
For compatibility with old code, set-input-port/state!
and
set-output-port/
are synonyms for this procedure.
state!
procedure+: port/operation port object
Returns the operation named object in port. If port
has no such operation, returns #f
.
For compatibility with old code, input-port/operation
and
output-port/operation
are similar to port/operation
. They
differ in that they translate certain old operation names to new
equivalents before calling port/operation
.
input-port/custom-operation
and
output-port/custom-operation
are synonyms for
input-port/
and
operationoutput-port/operation
,
respectively.
procedure+: port/operation-names port
Returns a list whose elements are the names of the operations supported
by port
. The list is not newly allocated and must not be
modified.
For compatibility with old code, input-port/operation-names
and
output-port/
are synonyms for this procedure.
operation-names
procedure+: make-eof-object input-port
Returns an object that satisfies the predicate eof-object?
. This
is sometimes useful when building input ports.
Go to the previous, next section.