(Semi) first look at Clojure

OK, it's time for Clojure (again). Let's look at the (now famous :) Fibonacci function:

(defn fib [n]
(if (< n 2)
n
(+ (fib (- n 1))
(fib (- n 2)))))
(time
(doseq [n (range 40)]
(prn (format "Fib(%s) = %s" n (fib n)))))
view raw gistfile1.clj hosted with ❤ by GitHub

It took ~9 seconds which's not so good as would be (however, I'm not very frustrated about that :)
What about the language itself, it feels very 'tired' - it has little build-in constructs and, I believe, it's extremely flexible. Time will tell if I'm right... :)
However, there's one annoying thing - lazy sequences, which I almost hate in C# (IEnumerable) because they must not be mixed with any side effects, which is rather hard to achieve in such a primarily imperative language as C#. So, I have a believe that laziness is very much nicer in Clojure :)  

Comments

Popular posts from this blog

Regular expressions: Rust vs F# vs Scala

Hash maps: Rust, F#, D, Go, Scala

Haskell: performance