Clojure 为什么大猩猩会抛出“无法解析符号”错误?
Clojure 为什么大猩猩会抛出“无法解析符号”错误?,clojure,require,Clojure,Require,:require在中似乎不起作用。我打开一个新会话并运行以下操作: (ns pacific-iceberg (:require [gorilla-plot.core :as plot])) (defn f [x] (Math/pow x 2)) (plot f [-9 9]) 输出: An exception was caused by: java.lang.RuntimeException (Unable to resolve symbol: plot in this context)
:require
在中似乎不起作用。我打开一个新会话并运行以下操作:
(ns pacific-iceberg
(:require [gorilla-plot.core :as plot]))
(defn f [x] (Math/pow x 2))
(plot f [-9 9])
输出:
An exception was caused by: java.lang.RuntimeException (Unable to resolve symbol: plot in this context)
...
发生了什么事?你把
:as
和:refere
弄糊涂了。Clojure的require
解释:
公认的选择:
:as将符号作为其参数,并将该符号作为
当前命名空间中的lib命名空间
:refere从名称空间或:all中获取要引用的符号列表
关键字以引入所有公共变量
如果你想要一个名为“plot”的函数,并且你想引用它而不使用名称间隔,请使用
:refereplot
,但是如果你想使名称空间显式(我的偏好),那么就使用类似:as gorilla
的东西,然后用gorilla/plot
来调用它,对吧。我应该使用(plot/plot f[-9])
。谢谢!工作起来很有魅力!