I read somewhere Clojure is compiled. Is it really compiled, like Java or Scala, rather than interpreted, like Jython or JRuby?
相关问题
- Angular: ngc or tsc?
- Better Sequence Duplicate Remover
- Where is the implementation of included C++/C head
- Installation of Leiningen 2.X in Mac OS X
- Questions about Lists and other stuff in Clojure
相关文章
- Factor Clojure code setting many different fields
- Does learning one Lisp help in learning the other?
- php module does not compile. Does not recognize “s
- Why does the C++ compiler give errors after lines
- Compile drools guided decision table into rules
- Better way to nest if-let in clojure
- Idiomatic approach for structuring Clojure source
- Mvn compile before exec
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)
: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.
Clojure is a compiled JVM language. That means that the first step it takes when confronted with a new program is to compile it to JVM bytecode.
Some of the JVM bytecode may later be compiled to machine code by HotSpot, if you're using OpenJDK or a derivative of it.
As a high-level language, Clojure has a form of dynamic typing, which is what the "completely dynamic" phrase is referring to.
Both-ish! (when it comes to generating bytecode)
Clojure is on-the-fly-compiled at code load time into JVM bytecode, which has the feeling and flow of an interpreted language, and ahead-of-time compiled into JVM bytecode, which has the flow of a compiled language. both of these are then JIT compiled into machine code by the Java Hotspot compiler which takes care of the dynamic optimization that Clojure depends on for speed. just to make things interesting "loaded/evaluated" code can compile on the fly at runtime, and AOT compiled code can load and evaluate source at runtime.
(load "/my/file.clj")
from the repl.In this case when i mention compiling vs. interpreting I should be clear that I am talking about turning source code into JVM bytecode. All JVM languages are compiled by the JVM at runtime so that distinction is not really very interesting.