不能在 lein repl 中要求第三方库
Can not require third-party library in lein repl
- clojure 版本:1.8.0
- leiningen 版本:2.7.1
- jdk版本:1.8.0_101
当我需要一个库时,说 reagent
(已添加到项目依赖项中),在 lein repl 中:
user=> (require '[reagent.core :as r])
nil
输出为nil,我认为这意味着成功。但是当我使用 r
时,比如说 (r/atom 3)
,repl 抛出一个错误说:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: r in
this context, compiling: (/private/var/folders/_y/n3ym4ftj2ld9tl471g_kcv_00000gn/T
/form-init1002540725014588615.clj:1:4923)
这似乎很奇怪。
有人知道吗?
顺便说一下,我可以要求 java 和 clojure 库。
您可能正在尝试使用 ClojureScript 库:Clojure REPL 中的试剂。查找错误原因并没有多大用处,因为 Clojure 和 ClojureScript 假设在非常不同的环境中 运行,分别是 JVM 和 JavaScript。但同样的尝试将在 ClojureScript 上下文中成功。
作为测试,基于 figwheel 模板创建一个 ClojureScript 项目。
lein new figwheel rtest
cd rtest
在project.clj
中添加摄政依赖
:dependencies [[org.clojure/clojure "1.8.0"]
[reagent "0.6.0"] ; only add this line
运行 项目
rlwrap lein figwheel
您将自动连接到浏览器repl。否则浏览至 http://localhost:3449/index.html 以建立连接。
现在您可以重试之前的操作了。
cljs.user=> (require '[reagent.core :as r])
nil
cljs.user=> (type r/render-component)
#object[Function "function Function() { [native code] }"]
- clojure 版本:1.8.0
- leiningen 版本:2.7.1
- jdk版本:1.8.0_101
当我需要一个库时,说 reagent
(已添加到项目依赖项中),在 lein repl 中:
user=> (require '[reagent.core :as r])
nil
输出为nil,我认为这意味着成功。但是当我使用 r
时,比如说 (r/atom 3)
,repl 抛出一个错误说:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: r in
this context, compiling: (/private/var/folders/_y/n3ym4ftj2ld9tl471g_kcv_00000gn/T
/form-init1002540725014588615.clj:1:4923)
这似乎很奇怪。 有人知道吗?
顺便说一下,我可以要求 java 和 clojure 库。
您可能正在尝试使用 ClojureScript 库:Clojure REPL 中的试剂。查找错误原因并没有多大用处,因为 Clojure 和 ClojureScript 假设在非常不同的环境中 运行,分别是 JVM 和 JavaScript。但同样的尝试将在 ClojureScript 上下文中成功。
作为测试,基于 figwheel 模板创建一个 ClojureScript 项目。
lein new figwheel rtest
cd rtest
在project.clj
中添加摄政依赖:dependencies [[org.clojure/clojure "1.8.0"]
[reagent "0.6.0"] ; only add this line
运行 项目
rlwrap lein figwheel
您将自动连接到浏览器repl。否则浏览至 http://localhost:3449/index.html 以建立连接。
现在您可以重试之前的操作了。
cljs.user=> (require '[reagent.core :as r])
nil
cljs.user=> (type r/render-component)
#object[Function "function Function() { [native code] }"]