;;;; ;;;; Standard strings in Lisp are immutable. There seem to be two ;;;; relatively easy ways around this problem: ;;;; ;;;; 1) Use what C++ would call an ostringstream: ;;;; ;;;; (defvar s (make-string-output-stream)) ;;;; (format s "~a~%" "Hello, World!") ;;;; (format s "~a~%" "Goodbye, Cruel World!") ;;;; (get-output-stream-string s) ;;;; ;;;; The only problem with this is that the call to ;;;; (get-output-stream-string) resets s making it hard to ;;;; append to s later. ;;;; ;;;; 2) Strings in lisp are vectors of characters. It doesn't ;;;; matter if the vector is adjustable or not. This is the ;;;; approach taken in the code below. Note that the code uses ;;;; macros to avoid unnecessary function calls. ;;;; ;;;; Also see the dstring2.lisp file for an equivalent class that is ;;;; implemented using lists of characters instead. ;;;; (defmacro dstring () `(make-array 0 :fill-pointer 0 :adjustable t :element-type 'character)) (defmacro dstring->string (s) s) (defmacro dstring->list (s) `(coerce ,s 'list)) (defmacro dstring-append (s x) `(format ,s "~a" ,x)) (defmacro dstring-append-char (s c) `(format ,s "~a" ,c)) (defmacro dstring-append-line (s &optional (x "")) `(format ,s "~a~%" ,x)) (defmacro dstring-clear (s) `(setf (fill-pointer ,s) 0))