Allows access to the input buffer.
An input stream.
The value returned by
allows access to the state of the input buffer for the given buffered stream.
should be an instance of a subclass of buffered-stream.
Within the code
, the variables
are bound to the buffer of
, its current index and the limit of the buffer. Setting
will change the values in the stream
but note that other changes to these values (for example, by calling other stream functions) will not affect the values bound within the macro. See the example for a typical use which shows how this restriction can be handled.
The buffer is always of type
. The stream-element-type of
depends on how it was constructed.
The index is the position of the next element to be read from the buffer and the limit is the position of the element after the end of the buffer. Therefore there is no data in the buffer when
is greater than or equal to
This example function returns a string with exactly four characters read from a buffered stream. If
is reached before four characters have been read, it returns
(defun read-4-chars (stream)
(declare (type stream:buffered-stream stream))
(let ((res (make-string 4))
;; Outer loop handles buffer filling.
;; Inner loop handles buffer scanning.
(loop (stream:with-stream-input-buffer (buf ind lim) stream
(when (>= ind lim)
;; End of buffer: try to refill.
(setf (schar res elt) (schar buf ind))
(when (= elt 4)
(return-from read-4-chars res))))
(unless (stream:stream-fill-buffer stream)
(return-from read-4-chars nil)))))
LispWorks User Guide and Reference Manual - 22 Dec 2009