Is Clojure compiled or interpreted?

OscarRyz picture OscarRyz · Apr 14, 2011 · Viewed 7.2k times · Source

I read somewhere Clojure is compiled. Is it really compiled, like Java or Scala, rather than interpreted, like Jython or JRuby?

Answer

mikera picture mikera · Apr 14, 2011

Clojure is always compiled.

The Clojure compiler produces Java byte code, which is typically then JIT-compiled to native code by the JVM.

The thing that can be confusing is the dynamic and interactive nature of Clojure that means you can invoke the compiler at run-time if you want to. This is all part of the Lisp "code is data" tradition.

For example, the following will invoke the Clojure compiler at run-time to compile and execute the form (+ 1 2):

(eval '(+ 1 2))
=> 3

The ability to invoke the compiler at run-time is very useful - for example it enables you to compile and run new code in the middle of a running Clojure application by using the REPL. But it's important not to confuse this "interactive" style of development with being "interpreted" - Clojure development is interactive, but still always compiled.