3 ms·
(comment) doesn't completely ignore the body, which is weird for something that is supposed to be a comment https://clojuredocs.org/clojure.core/comment https:/
by fmakunbound 6y ago
(comment) doesn't completely ignore the body, which is weird for something that is supposed to be a comment https://clojuredocs.org/clojure.core/comment https://clojuredocs.org/clojure.core/comment
; and ;; pretty usage is same as Common Lisp. #_ is replaced with #+nil in Common Lisp which is just a reader macro. ;;; is usually reserved for prose, and of course there's #| commenthere |# which is just another reader macro, and is suitable for code examples, where you can probably still eval it in your text editor.
- fnordsensei 6y agoYep, look at the implementation: (defmacro comment "Ignores body, yields nil" {:added "1.0"} [& body]) A macro that takes any number of arguments and does absolutely nothing. This is still a macro invocation, so the arguments must not cause a reader error.
- eigenhombre 6y agoI sometimes teach macro writing basics at work, with exercises -- writing this macro is always Exercise One. It is a common pitfall to write non-readable content in a comment expression, which can certainly be confusing to newcomers who are used to less stringent multiline comments like /* ... */ or triple-quoted strings in Python.
- capableweb 6y agoI think it makes sense, because there are two types of comments here. First is "ignore everything" which is handled by ";" but then there is the function "comment" or "rich comment" that should still be valid code and all dependencies it needs available. If not, someone couldn't open the file and run the forms inside the block as-is, so the program is not valid. It's a gotcha, but in the end I think it's neat that it makes sure it's valid.
- monsieurbanana 6y agoI don't know if it's a voluntary feature, or if it was just faster to implement that way, but personally I see it as an advantage. Rich comments are not just the equivalent of a multiligne comments in other languages, I expect the statements inside of it to be run, often many times, during normal clojure development. I don't want to have broken code inside.