【问题标题】:Can not require third-party library in lein repllein repl 中不能需要第三方库
【发布时间】:2016-12-05 10:40:24
【问题描述】:
  • clojure 版本:1.8.0
  • leiningen 版本:2.7.1
  • jdk 版本:1.8.0_101

当我需要一个库时,说reagent(已在项目依赖项中添加),在 lein repl 中:

user=> (require '[reagent.core :as r])
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) 

这似乎很奇怪。 有人有什么想法吗?

顺便说一句,我可以 require java 和 clojure 库。

【问题讨论】:

  • Reagent 主要是一个 ClojureScript 库。核心命名空间只有一个实用宏。你是从 ClojureScript REPL 运行它吗?
  • 您能否详细说明when I use the r 的含义...您如何使用它?只需在 REPL 中输入r 并按回车键就会导致此错误,因为r 不是符号。您需要引用一个符号,例如:(r/my-function ... 因此,如果没有更多信息,很难说您的问题是什么。
  • @MichielBorkent 是的,这是一个尴尬,我可能会忽略 clojure REPL 和 clojurescript REPL 的区别..

标签: clojure leiningen


【解决方案1】:

您可能正在尝试使用 ClojureScript 库:Clojure REPL 中的试剂。找到错误的原因并不是那么有用,因为假设 Clojure 和 ClojureScript 运行在非常不同的环境中,分别是 JVM 和 JavaScript。但是在 ClojureScript 上下文中,同样的尝试会成功。

作为测试,创建一个基于 figwheel 模板的 ClojureScript 项目。

lein new figwheel rtest
cd rtest

在project.clj中添加regent依赖

: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 和 clojurescript 的运行环境的区别我还不是很清楚。谢谢!
猜你喜欢
  • 1970-01-01
  • 2013-09-19
  • 2012-03-20
  • 1970-01-01
  • 2017-08-18
  • 2011-10-05
  • 1970-01-01
  • 1970-01-01
  • 2011-09-04
相关资源
最近更新 更多