Block Comments in Clojure

Viewed 37280

How do I comment multiple lines in Clojure?

10 Answers

Actually, there is a way!


(comment

(defn hey [] ("Hey there!"))

Check me out! )

Just wrap your comments in (comment ..) :)

Have fun!

Clojure supports a #_ reader macro which completely skips the next form. This is mentioned on the page about the Clojure Reader. There is also the comment macro which has a similar effect, but is implemented differently.

Both the above require that the thing that you're commenting out is otherwise a syntactically correct S-expression.

Some Lisp dialects have a multi-line comment that can contain arbitrary text, but I don't see one for Clojure.

For a long comment block, Macros #_ or (comment ...) didn't work as proprietarily, then I did comment block with VSCODE(OS X).

  1. Highlight the comment block.
  2. press command+shift+p in vscode.
  3. find "Add Line Comment"

Clojure also supports a double #_ #_ reader macro which completely skips the next two forms. Very useful for commenting out a key and multi-line value in a map.

Example

{
:db-connector "jdbc"
#_ #_ :auto-offset-reset    {:dev     "earliest"
                             :default "latest"}
}
Related