有什么区别:
(require '[some-package.sub as some])
(require 'example.core)
Run Code Online (Sandbox Code Playgroud)
和
(require [some-package.sub as some])
(require example.core)
Run Code Online (Sandbox Code Playgroud)
我什么时候应该使用另一个?只有带撇号的那个在REPL环境中工作.
require是一个函数((source require)在REPL中检查).因此,在其自己的评估之前评估其参数.
在您调用require时,符号some-package.sub将解析(points)为空,因此您将获得"无法解析符号:the-symbol-that-points-to-nothing在此上下文中... "
但是,如果您引用上述符号,我们可以进行实际评估require.因此require,由于它是一种功能,因此需要引用的形式.
现在ns是一个宏((source ns)在REPL中检查).因此,在扩展之前不评估其参数.从技术上讲,它可以采用免费符号或引用形式,但决定使用原始的自由符号.(ns lalala (:require [some-package.sub :as some]))
No-ooo-ow,当你调用require(函数)时a,你实际上需要一个解析为var的符号.
(def a 'B)
(require a)
FileNotFoundException Could not locate B__init.c;ass or B.clj on the classpath[...]
Run Code Online (Sandbox Code Playgroud)
......那是因为需要是一种功能.
希望它有所帮助.
| 归档时间: |
|
| 查看次数: |
280 次 |
| 最近记录: |