I think there are about 666 parentheses in those code examples.. I don't get the appeal of Clojure?
Curiously, the equivalent code in most other languages has about the same number of parens.
You can just do:
let fibs = 1 : 1 : [ fibs !! n + fibs !! (n - 1) | n <- [1..] ]
for the Fibonacci sequence and take 10 $ iterate (succ . recip) 1
for the first 10 iterations of the continued fraction.To me these read much more clearly but then I haven't written anything big in a lispy language yet.
(def fibo (map second
(iterate (fn [[x y]] [y (+ x y)]) [0 1])))
I just went with a different version for the article to show another way of doing it that might be clearer to someone new to Clojure. As for understanding/ease of reading, the Haskell version is a little more alien to me, but that's because I haven't spent much time in Haskell.Once again, for your CF ex:
(take 10 (iterate (comp inc /) 1))
Which gives ratios in Clojure, not doubles. Both elegant solutions, definitely. I just wanted to use my GCF, which could probably be made to look a little nicer as well. This post was more about playing around with the Golden Ratio than writing sexy code (though admittedly, I probably could have done better in many places!)Haskell is a really cool language: I'm making my way through Real World Haskell right now!
Which is indeed what happened with me, I saw indentation and would e.g. use that to get the right number of closing parens in a function and at the same time detect a certain class of mistakes.
Give a Lisp an honest try (Scheme is simpler than Clojure) and you might find it works for you.