News for hackers. Stuff that matters.
Re:Introduction to Clojure by alrex021 on Saturday October 17, 2009 @12:14PM (#887088)
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!!!

Re:Introduction to Clojure by jacquesm on Saturday October 17, 2009 @02:14PM (#887208)
> 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 ?

Re:Introduction to Clojure by alrex021 on Saturday October 17, 2009 @03:17PM (#887304)
-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.

Re:Introduction to Clojure by jacquesm on Saturday October 17, 2009 @03:29PM (#887318)
Ah 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.