LispWorks User Guide and Reference Manual > 20 User Defined Streams > 20.2 An illustrative example of user defined streams


20.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 file-stream slot. When making an instance of unicode-ls-stream we can create an instance of a Common Lisp file stream in this slot. This allows us to use the Common Lisp file stream functionality for reading from and writing to a file.

LispWorks User Guide and Reference Manual - 22 Dec 2009