I wrote the other day about Zach Beane’s new Common Lisp Tips blog. Yesterday, he had a really nifty tip that solves a common problem. We’ve all had situations where we want to output something like
Processed 1 file.
Processed 23 files.
Some people are lazy and you end up with
Processed 1 files.
which I always find jarring. In Emacs Lisp we might solve this problem with something like
(print (format "Processed %d file%s" n (if (> n 1) "s." ".")))
and something very similar involving a
printf in C.
Common Lisp has a special format directive that takes care of this automatically. What do you expect, after all, from a language that even has a directive for outputting numbers in Roman Numerals? This is Beane’s tip so I’ll direct you to his post for the details. If you’re a Lisp programmer and, like me, you didn’t already know about this, you should definitely head over and take a look.