Next: , Previous: Library data structures, Up: Libraries


6.5 I/O extensions

These facilities are all exported from the extended-ports structure.

Tracking ports track the line & column number that they are on.

— procedure: make-tracking-input-port sub-port –> input-port
— procedure: make-tracking-output-port sub-port –> output-port

Tracking port constructors. These simply create wrapper ports around sub-port that track the line & column numbers.

— procedure: current-row port –> integer or #f
— procedure: current-column port –> integer or #f

Accessors for line (row) & column number information. If port is a not a tracking port, these simply return #f.

— procedure: fresh-line port –> unspecified

This writes a newline to port with newline, unless it can be determined that the previous character was a newline — that is, if (current-column port) does not evaluate to zero.

These are ports based on procedures that produce and consume single characters at a time.

— procedure: char-source->input-port char-producer [readiness-tester closer] –> input-port
— procedure: char-sink->output-port char-consumer –> output-port

Char-source->input-port creates an input port that calls char-producer with zero arguments when a character is read from it. If readiness-tester is present, it is used for the char-ready? operation on the resulting port; likewise with closer and close-input-port. Char-sink->output-port creates an output port that calls char-consumer for every character written to it.

Scheme48 also provides ports that collect and produce output to and from strings.

— procedure: make-string-input-port string –> input-port

Constructs an input port whose contents are read from string.

— procedure: make-string-output-port –> output-port
— procedure: string-output-port-output string-port –> string
— procedure: call-with-string-output-port receiver –> string

Make-string-output-port makes an output port that collects its output in a string. String-output-port-output returns the string that string-port collected. Call-with-string-output-port creates a string output port, applies receiver to it, and returns the string that the string output port collected.

Finally, there is a facility for writing only a limited quantity of output to a given port.

— procedure: limit-output port count receiver –> unspecified

Limit-output applies receiver to a port that will write at most count characters to port.