How do I comment multiple lines in Clojure?
For a long comment block, Macros #_ or (comment ...) didn't work as proprietarily, then I did comment block with VSCODE(OS X).
Double quotes (string literal) allow adding arbitrary text (not only proper S-forms):
(comment "
public class HelloWorld {
public static void main(String[] args) {
System.out.print("Hello, World");
System.out.println();
}
}
")
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
When using emacs and cider, there's a command M-x comment-region
which I use often.
See this link: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips
You can create multiline comments with the syntax
(comment .....
....)
In Emacs you can use the command M-;
(the shortcut for M-x comment-dwim
). It will comment or uncomment any marked region of text/code, so, as long as your entire function or set of functions is included in the region, you can comment or uncomment that region quite easily. The Emacs reference manual for the function M-;
can be found here.