Block Comments in Clojure

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

How do I comment multiple lines in Clojure?

9条回答
  •  长情又很酷
    2021-01-31 01:24

    There are multiple ways that I know:

    First one is using the comment macro: it only does not evaluates all the code inside the comment body (but it still checks for balanced parenthesis/brackets). If you know your way with paredit, it won't take much time if you want to comment a few sexp calls.

    (comment 
     (println 1))
    

    However, it will still check for parenthesis match. So if you have unbalanced parenthesis, you code won't compile (yielding java.lang.RuntimeException: EOF while reading).

    Another way is using #_ (aka the discard macro): it will discard the next sexp, which is the way I personally prefer (faster to type and normally I do that on sexps when I have to debug):

    #_(println 1)
    

    It also checks for unmatched delimiters: so if you have unbalanced parenthesis, it won't compile as well.

    Lastly, there is the ; character which will comment the line (similar to the other languages commentary feature) and the compile will ignore it completely. If you want to comment multiple lines, you need to prepend all the lines with ; , which are normally a hassle, but usually text editors will do it for you with a command after selecting multiple lines.

    ;  (println 1)
    ;  (println 1 also won't break
    

提交回复
热议问题