commonlisp | Functions | with-output-to-string
with-output-to-string
External Link: Macro WITH-OUTPUT-TO-STRING.
The macro WITH-OUTPUT-TO-STRING can be used to create a string output stream, and return the resulting string at the end.
with-output-to-string (var &optional string-form &key element-type)
declaration* form*
=> result*
element-type specifier is defaulted to character.
form* is implicit progn
with-output-to-string creates a character output stream and performs a series of operation that output to the result. automatically closed on exit side effect: the string is modified
(with-output-to-string (str)
(write-line "Foobar!" str)
(write-string "Barfoo!" str))
;=> "Foobar!
; Barfoo!"
(let ((str (make-string-output-stream)))
(write-line "Foobar!" str)
(write-string "Barfoo!" str)
(get-output-stream-string str))
