Redirecting output
Got a function that writes to *standard-output* but you really want to redirect it somewhere else? You can bind the *standard-output* special variable in all the macros that create temporary streams.
For example, to return the output as a string:
* (with-output-to-string (*standard-output*)
(print-marketing-report))
"Source,Hits
twitter,243
google,805
direct,47
"
To write it out to a file:
* (with-open-file (*standard-output* #p"file.txt" :direction :output)
(print-marketing-report))
NIL