Block Comments in Clojure

后端 未结 9 1430
渐次进展
渐次进展 2021-01-31 01:13

How do I comment multiple lines in Clojure?

相关标签:
9条回答
  • 2021-01-31 01:34

    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.

    0 讨论(0)
  • 2021-01-31 01:36

    Actually, there is a way!

    
    (comment

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

    Check me out! )

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

    Have fun!

    0 讨论(0)
  • 2021-01-31 01:36

    Other examples are great, I'd just like to add one more trick:

    Sometimes you want to comment out a few lines of code, but still have the compiler compile it and report any errors (e.g. a set of commands in a top-level namespace that you plan to execute later at the REPL).

    In this case I like to wrap the code with (fn [] .....) which means that it still gets compiled, it just doesn't get called.

    0 讨论(0)
提交回复
热议问题