Does anyone else find Clojure's syntax a bit obtuse? I feel like basic recursive definitions are much clearer in Haskell and ML. To sum over a list using an accumulator shouldn't take more than two or three trivial lines of code.
On the other hand, viewed as a DSL for the JVM implemented as a Java library or as an evolutionary step in Lisp, Clojure's syntax makes a lot more sense.
Summing over a collection is a one liner in Clojure (as in many other languages):
=> (reduce + (range 10))
45
Clojure's dynamic typing trades simplicity of syntax for the static typing safety harness required in ML or Haskell. (defn sum-acc
([xs] (sum-acc xs 0))
([[x & xs] acc]
(if (nil? x)
acc
(recur xs (+ x acc)))))
Could you show Haskell equivalent?BTW there should be a macro that adds argument with default value.
sumacc xs = summer xs 0
where summer [] n = n
summer (x:xs) n = summer xs (x+n)
I'm sure there are macros in some library somewhere that implement pattern matching in lisp (regardless of dialect).But obviously summing over a list can be done in one line of code in any decent language even without pattern matching.