April 3rd, 2004

(no subject)

When I first used format, I painted myself into a lot of corners where I thought I had to dynamically build format strings. I can't even remember the exact situations, but I distinctly remember bits of code that looked like:

(format t (format nil "...") ...)

Then I learned about ~?, and stopped doing that, mostly.

Then today I was going to patch up SBCL's profile reporting, because sometimes its summary columns get out of whack from results that are too big. So I read section 22.3 a little more closely, and discovered the use of V in a format directive's argument list, and wound up with something like this in the end:

(dolist (time-info time-info-list)
  (format *trace-output* "~v,3F | ~v:D | ~v:D | ~10,6F | ~S~%"
	  seconds-width (time-info-seconds time-info)
	  consed-width (time-info-consing time-info)
	  calls-width (time-info-calls time-info)
	  (/ (time-info-seconds time-info)
	     (float (time-info-calls time-info)))
	  (time-info-name time-info)))

It's nice when the tools anticipate and accomodate your needs.