Thomas F. Burdick <tfb@conquest.OCF.Berkeley.EDU> wrote:
+---------------
| In general, I'd say the with-output-to-string approach is a
| nice compromise between making the code easy for human consumption
| and realistically optimizable.
+---------------
Especially since -- if you *do* happen to have a good guess as to
the result size -- you can provide WITH-OUTPUT-TO-STRING with an
initially-sized adjustable string to use as a starting point, as
in the example in the CLHS [slightly tweaked]:
> (let ((string (make-array '(100) :element-type 'base-char
:fill-pointer 0
:adjustable t)))
(with-output-to-string (s string)
(format s "Here's some output")
(format s " and some more output")
(format s " and some more.")
(format s " All done."))
string)
"Here's some output and some more output and some more. All done."
> (length *)
64
>
-Rob
p.s. CLHS-reading exercise for the newcomer: Why won't the following work?
(with-output-to-string (s (make-array '(100) :element-type 'base-char
:fill-pointer 0
:adjustable t))
(format s "Here's some output")
(format s " and some more output")
(format s " and some more.")
(format s " All done."))
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607