19.2.1 Defining a new stream class

Streams can be capable of input or output (or both), and may deal with characters or with binary elements. The stream 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:

(defclass unicode-ls-stream 
  ((file-stream :initform nil 
                :initarg :file-stream
                :accessor ls-stream-file-stream)))

The new class, unicode-ls-stream , has fundamental-character-input-stream and fundamental-character-output-stream 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 file-stream . This slot is a place holder for a Common Lisp file stream. When making an instance of unicode-ls-stream 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.





Package: stream

The classes fundamental-character-input-stream and fundamental-character-output-stream 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.

LispWorks User Guide - 8 Apr 2005