Posts in category lisp

Why not Clojure

#summary Clojure isn't a Lisp.

What's wrong with Clojure?

Clojure is not Lisp. It is some looking-like-lisp language that somehow compiles into Java bytecode with some features of a Lisp, such a prefix notation, reader and even macros.

There is one of the very essential abilities of a Lisp as a language. This is citation from the original John McCarthy paper:

d. Recursive Function Definitions. By using conditional expressions we can, without circularity, define functions by formulas in which the defined function occurs.

For example, we write n! = (n = 0 → 1, T → n · (n − 1)!)

which means exactly this:

(define (factorial n)
   (if (= n 0)
      (* n (factorial (- n 1)))))

But what we got in idiomatic Clojure is this imperative nonsense:

(def factorial
  (fn [n]
    (loop [cnt n acc 1]
       (if (zero? cnt)
          (recur (dec cnt) (* acc cnt))))))

So, we cannot define a function recursively. We must use imperative looping instead. That is not Lisp way.

The lack of tail call optimization is not the issue, and usage of a loop macro stolen from Common Lisp with this recur hack doesn't make it more Lisp-ish. We cannot express our idea clearly, without avoiding useless state variables.