Note: Rich Comment Blocks in Common Lisp

July 9, 2024
lisp

In Clojure, “Rich Comment Blocks” serve as both a playground and a log during development. Named after Clojure’s creator, Rich Hickey, these blocks offer a unique approach to REPL-driven development.

Stuart Halloway, in his talk “Running with Scissors,” quipped:

These comments are rich because they provide rich detail about the development process and because they were written by a person named Rich.

Rich Comment Blocks look like this:

(comment
  (println "foo"))

When the program runs, it ignores the top-level form. However, during development, you can evaluate each line individually, making it an invaluable tool for experimentation and debugging.

As a Common Lisp user, I initially missed this feature. While Common Lisp does have the #+nil reader macro that can be used for similar purposes, it’s not quite as flexible as Clojure’s comment form. The #+nil macro looks like this:

#+nil
(print "This won't be evaluated when the file is loaded")

However, I wanted something closer to Clojure’s Rich Comment Blocks, so I created my own comment macro in Common Lisp:

(defmacro comment (&body body)
  (declare (ignore body)))

This simple macro brings the power of Rich Comment Blocks to Common Lisp, offering more flexibility than the #+nil reader macro. It allows you to wrap multiple expressions and even nested forms, which can be selectively evaluated during development.

Give it a try - you might find it as useful as I do.

Install Python on Ubuntu 24.04 Guile Hoot on the Mac