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*
                                                       ,stream)))
         ,@body))))

As in:

* (tee-to "/tmp/report.txt" (super-slow-report))
2006-02-25T04:55:04Z http://common-lisp.net/project/lisppaste/lisppaste2.3.tar.gz Lisppaste
2010-08-24T07:23:12Z http://weitz.de/files/hunchentoot.tar.gz hunchentoot
2009-12-04T16:21:48Z http://common-lisp.net/project/closer/ftp/aspectl_latest.tar.gz AspectL
2009-12-25T01:37:57Z http://common-lisp.net/project/bordeaux-threads/releases/bordeaux-threads.tar.gz Bordeaux-Threads
2010-08-03T18:16:13Z http://common-lisp.net/project/iolib/files/iolib-0.7.0.tar.gz IOlib
...

What kind of extra features could I add?