为什么大猩猩会抛出“无法解析符号”错误?

Why is Gorilla throwing an `unable to resolve symbol` error?

:require 似乎无法在 Gorilla 中工作。我打开一个新会话并 运行 以下内容:

(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:refer。 Clojure 的 require documentation 解释:

Recognized options:

:as takes a symbol as its argument and makes that symbol an alias to the lib's namespace in the current namespace.

:refer takes a list of symbols to refer from the namespace or the :all keyword to bring in all public vars.

如果你想要那个库中的函数 "plot" 你想引用它而不用名称间隔它,请使用 :refer plot,但如果你想使名称 space 显式(我的偏好)然后使用 :as gorilla 之类的东西然后用 gorilla/plot.

调用它