Streams can be capable of input or output (or both), and may deal with characters or with binary elements. The
package provides a number of stream classes with different capabilities from which user defined streams can inherit. In our example the stream must be capable of input and output, and must read characters. The following code defines our stream class appropriately:
((file-stream :initform nil
The new class,
as its superclasses, which means it inherits the relevant default character I/O methods. We shall be overriding some of these with more relevant and efficient implementations later.
Note that we have also provided a slot, called
. This slot is a place holder for a Common Lisp file stream. When making an instance of
we can create an instance of a file stream in this slot. This allows us to use the Common Lisp file stream functionality for reading from and writing to a file.
provide default methods for generic functions used for character input and character output respectively, and should therefore be included by stream classes concerned with these. The user can provide methods for these generic functions specialized on the user-defined classes.