September 14th, 2010

Random macro of the day

I wrote a report that gathers data from websites and prints the results, line by line, as they slowly come in. Here's a macro I made to watch the progress and save it to a file.

(defmacro tee-to (file &body body)
  (let ((stream (gensym "TEE")))
    `(with-open-file (,stream ,file :direction :output
                              :if-exists :supersede)
       (let ((*standard-output* (make-broadcast-stream *standard-output*

As in:

* (tee-to "/tmp/report.txt" (super-slow-report))
2006-02-25T04:55:04Z Lisppaste
2010-08-24T07:23:12Z hunchentoot
2009-12-04T16:21:48Z AspectL
2009-12-25T01:37:57Z Bordeaux-Threads
2010-08-03T18:16:13Z IOlib

What kind of extra features could I add?