Allows access to the output buffer.
with-stream-output-buffer (buffer index limit) stream &body body => result
buffer, index, limit
An output stream
The value returned by body.
with-stream-output-buffer allows access to the state of the output buffer for the given buffered stream.
stream should be an instance of a subclass of buffered-stream.
Within the code body, the variable names buffer, index and limit are bound to the buffer of stream, its current index and the limit of the buffer. Setting buffer, index or limit will change the values in the stream 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
simple-string. The stream-element-type of stream 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 index is greater than or equal to length.
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 User Guide and Reference Manual - 13 Feb 2015