I read somewhere Clojure is compiled. Is it really compiled, like Java or Scala, rather than interpreted, like Jython or JRuby?
Clojure is always compiled. The Clojure compiler produces Java byte code, which is typically then JIT-compiled to native code by the JVM.
Clojure is the result of all this. It's a LISP functional programming language running on the JVM designed for concurrent programs.
Clojure compiles all code you load on-the-fly into JVM bytecode, but sometimes it is advantageous to compile ahead-of-time (AOT). Some reasons to use AOT compilation are: To deliver your application without source. To speed up application startup. To generate named classes for use by Java.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With