5 ms·
Absolutely right. Don't arrange your parens to fall separately like author does on new lines. Let the parens flow after one another. The way your parens should
by alrex021 17y ago
Absolutely right. Don't arrange your parens to fall separately like author does on new lines. Let the parens flow after one another.
The way your parens should flow:
(def factorial
(fn [n]
(loop [cnt n acc 1]
(if (zero? cnt)
acc
(recur (dec cnt) (* acc cnt))))))
The author doesn't take an idiomatic approach to programming in Clojure in most of his code snippets.
[edit]
Throwing java.lang.Exception if a condition is not meat in your clojure functions? Don't do this either!!!
- jacquesm 17y ago> Throwing java.lang.Exception if a condition is not meat in your clojure functions? Don't do this either!!! What's the proper way of doing that in clojure ?
- licoresse 17y agoLike you saw, but it's not idiomatic to do so
- alrex021 17y ago-way- is not the problem here. The java.lang.Exception is. :-) Throw specialized "Runtime Exceptions" would be the way to go. For example throw IllegalArgumentException runtime exception if function call receives inappropriate arguments. You can also define your own specific (app-level) exception by proxying the RuntimeException or other relevant using the clojure's proxy macro.
- jacquesm 17y agoAh right! Apologies, I took it to mean that there was a better way of throwing an exception, not that particular one. Of course, that makes perfect sense.