Node:Ports, Next:, Up:Input and Output



27.1 Ports

[Concept of the port abstraction.]

Sequential input/output in Scheme is represented by operations on a port. Characters can be read from an input port and written to an output port. This chapter explains the operations that Guile provides for working with ports.

The formal definition of a port is very generic: an input port is simply "an object which can deliver characters on command," and an output port is "an object which can accept characters." Because this definition is so loose, it is easy to write functions that simulate ports in software. Soft ports and string ports are two interesting and powerful examples of this technique.

input-port? x Scheme Procedure
scm_input_port_p (x) C Function
Return #t if x is an input port, otherwise return #f. Any object satisfying this predicate also satisfies port?.

output-port? x Scheme Procedure
scm_output_port_p (x) C Function
Return #t if x is an output port, otherwise return #f. Any object satisfying this predicate also satisfies port?.

port? x Scheme Procedure
scm_port_p (x) C Function
Return a boolean indicating whether x is a port. Equivalent to (or (input-port? x) (output-port? x)).