Math 为什么我不能用Clojure代码访问我的Leiningen依赖项?
在Clojure中,如果我想引入Clojure.inspector函数,我可以这样做:Math 为什么我不能用Clojure代码访问我的Leiningen依赖项?,math,clojure,read-eval-print-loop,leiningen,Math,Clojure,Read Eval Print Loop,Leiningen,在Clojure中,如果我想引入Clojure.inspector函数,我可以这样做: (use `[clojure.math.numeric-tower :include (expt)]) 从REPL,我现在可以计算函数expt 然而,在我看来,应该(也可能是)有另一种方法来实现这一点——使用Leiningen依赖项引入代码 我将此行添加到我的project.clj: [org.clojure/math.numeric-tower "0.0.2"] 然后我重新启动REPL以拉入新的依赖项。
(use `[clojure.math.numeric-tower :include (expt)])
从REPL,我现在可以计算函数expt
然而,在我看来,应该(也可能是)有另一种方法来实现这一点——使用Leiningen依赖项引入代码
我将此行添加到我的project.clj:
[org.clojure/math.numeric-tower "0.0.2"]
然后我重新启动REPL以拉入新的依赖项。为了安全起见,我甚至做了“leindeps”(该命令没有输出)。当我尝试计算expt时,它会给我一个RuntimeException,并说它无法解析符号
仅使用Leiningen依赖项如何访问expt函数?您不能。它不是那样工作的。添加依赖项会将代码放在类路径上,这仅仅意味着它可供您使用。为了实际使用名称空间中的内容,您需要使用
(require '[the-namespace :refer [the things you want to use]])
或
或者在ns声明中执行上述任一操作(当不在REPL中并使用文件时)
(require '[the-namespace :as tn])
(tn/somevar)
(ns foo
(:require [the-namespace :as tn]))