Allows access to the output buffer.
An output stream
The value returned by body.
allows access to the state of the output buffer for the given buffered stream.
should be an instance of a subclass of buffered-stream.
Within the code
, the variable names
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 buffers are always of type
. The stream-element-type of
depends on how the stream was constructed.
The index is the position of the next free element in the buffer and the limit is the position of the element after the end of the buffer. Therefore the buffer is full when
is greater than or equal to
This example function writes a four character string to a buffered stream.
(defun write-4-chars (stream string)
(declare (type stream:buffered-stream stream))
(let ((elt 0))
;; Outer loop handles buffer flushing.
;; Inner loop handles buffer updating.
(loop (stream:with-stream-output-buffer (buf ind lim) stream
(when (>= ind lim)
;; Buffer full: try to flush.
(setf (schar buf ind) (schar string elt))
(when (= elt 4)
LispWorks Reference Manual - 6 Apr 2005