Clojure 是编译的还是解释的? [英] Is Clojure compiled or interpreted?

查看:24
本文介绍了Clojure 是编译的还是解释的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某处读到 Clojure 已编译.它真的是像 Java 或 Scala 那样编译的,而不是像 Jython 或 JRuby 那样解释的吗?

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

推荐答案

Clojure 总是编译.

Clojure 编译器生成 Java 字节码,然后通常由 JVM 将其 JIT 编译为本机代码.

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

令人困惑的是 Clojure 的动态和交互性质,这意味着您可以在运行时调用编译器.这是 Lisp代码即数据"传统的一部分.

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.

例如下面的代码会在运行时调用Clojure编译器来编译和执行(+ 1 2)的形式:

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

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

在运行时调用编译器的能力非常有用——例如,它使您能够使用 REPL 在正在运行的 Clojure 应用程序中编译和运行新代码.但重要的是不要将这种交互式"开发风格与被解释"混淆——Clojure 开发是交互式的,但仍然总是编译.

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 是编译的还是解释的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆