5 ms·
In clojure, you see something similar at the bottom of files: (comment (def some-state (create-state)) (some-fn [1 2 3]) (do-something some-state
by matthavener 11y ago
In clojure, you see something similar at the bottom of files:
(comment
(def some-state (create-state))
(some-fn [1 2 3])
(do-something some-state)
)
The compiler ignores the block, but in a REPL enabled editor, you can evaluate the forms to possibly view current state, or run functions that test behaviors or probe runtime state.
- krat0sprakhar 11y agoOr the equivalent #_(def some-state (create-state)) (some-fn [1 2 3]) (do-something some-state))
- vijaykiran 11y agoI guess you meant: #_((def some-state (create-state)) (some-fn [1 2 3]) (do-something some-state)) oh, and you can't have "invalid" code in (comment), but in #_ you can.
- okal 11y ago#_ comments out the form it precedes. You do not need to surround it with an extra pair of parentheses. Didn't know about the difference in behaviour with regard to invalid code. Thanks for that. EDIT: Leaving this here for context. I'd missed the fact that they weren't all enclosed in a single form to begin with. Parent's solution is correct in light of that.
- jorams 11y agoWhat your parent meant is that your #_ only comments out the first form, not the other two. Surrounding them all with an extra pair of parentheses groups them into a single form.
- okal 11y agoOops! I missed that. I wasn't looking closely enough, so it seemed to me like they were all enclosed in a single form to begin with. Thanks.
- krat0sprakhar 11y agoYup you're right! I made the same mistake as okal and assumed everything is in one form! Also, I didn't know about the 'invalid' code part - so thanks for that :)