clojurecompilationjvm-languagesinterpreted-languagecompiled-language

Is Clojure compiled or interpreted?


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


Solution

  • 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.