Introduction to Clojure
cio.com.au
cio.com.au
Edit: There are other style problems with this article. Worst is probably this one:
Bad: (map (fn [x] (fibonacci x)) [1 2 3 5 6 7 8 9 10])
Good: (map fibonacci (range 1 11))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!!!
What's the proper way of doing that in clojure ?
You can also define your own specific (app-level) exception by proxying the RuntimeException or other relevant using the clojure's proxy macro.
Of course, that makes perfect sense.
My 'C' parser keeps telling me 'wrong bracket' though :)
The solution is to use the right tool for the job. Emacs has something called paredit-mode that relieves you of having to type the closing parens.
Yes! I can't do without it now. BTW somebody told me Paredit is a port of the old Interlisp structured editor.
There's also http://news.ycombinator.com/item?id=877386, if you haven't seen it.
Whenever I'm programming in a non-Lisp language, I really miss those kinds of editor features that are enabled by having an idiot-simple syntax.