Chapter 7: Input and Output


Overview

click to expand

A six-armed spiral.

All input and output operations are performed through ports. A port is a pointer into a (possibly infinite) stream of characters (typically a file), an opening through which programs may draw characters or objects from the stream or place characters or objects into the stream.

Ports are first-class objects, like any other object in Scheme. Like procedures, ports do not have a printed representation the way strings and numbers do, so they are shown here with the notation #<port>. There are initially two ports in the system: the current input port and the current output port. In an interactive session, these ports usually point to the terminal input and output streams. Several ways to open new ports are provided.

An input port often points to a finite stream, e.g., an input file stored on disk. If one of the input operations (read, read-char, or peek-char) is asked to read from a port that has reached the end of a finite stream, it returns a special eof (end of file) object. The predicate eof-object? may be used to determine if an object returned from read, read-char, or peek-char is an eof object.




The Scheme Programming Language
The Scheme Programming Language
ISBN: 026251298X
EAN: 2147483647
Year: 2003
Pages: 98

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net