I/O Ports

A port is an abstraction of an input or output device:

(input-port? obj )
(output-port? obj )

A file is, logically, a sequence of characters. A port can be created for a file by opening the file, either for input or output.

(open-input-file filename )
(open-output-file filename )

The filename is a string; these functions return a port that may then be used for I/O. Each of the I/O functions in Scheme allows an optional port argument.

When a program is finished with a file, the file must be closed.

(close-input-port port )
(close-output-port port )

Contents    Page-10    Prev    Next    Page+10    Index