我正在尝试使用 expt
功能根据 this answer但是当我尝试做 (use 'clojure.math.numeric-tower)
在 REPL 我收到错误
user> (use 'clojure.math.numeric-tower)
(use 'clojure.math.numeric-tower)FileNotFoundException Could not locate clojure/math/numeric_tower__init.class or clojure/math/numeric_tower.clj on classpath: clojure.lang.RT.load (RT.java:443)
我想我需要按照解释 here 放入 Leiningen 依赖信息
[org.clojure/math.numeric-tower "0.0.2"]
在我的
project.clj
,我这样做了,但我仍然遇到同样的错误。我究竟做错了什么?编辑
As in this answer我去了我的项目目录并做了
lein deps
a@b:~/command-line-args$ lein deps
Retrieving org/clojure/math.numeric-tower/0.0.2/math.numeric-tower-0.0.2.pom from central
Retrieving org/clojure/math.numeric-tower/0.0.2/math.numeric-tower-0.0.2.jar from central
a@b:~/command-line-args$
但我在 REPL 中仍然遇到同样的错误。
编辑 2
根据 Vidya 的回答,我正在尝试使用 Pomegranate 但没有成功。这是我尝试过的。我究竟做错了什么:
user> (use '[cemerick.pomegranate :only (add-dependencies)])
nil
user> (add-dependencies :coordinate '[[org.clojure/math.numeric-tower "0.0.2"]]
:repositories (merge cemerick.pomegranate.aether/maven-central
{"clojars" "http://clojars.org/repo"}))
{}
user> (require '(numeric-tower core stats charts))
FileNotFoundException Could not locate numeric_tower/core__init.class or numeric_tower/core.clj on classpath: clojure.lang.RT.load (RT.java:443)
user> (require 'clojure.contrib.math)
FileNotFoundException Could not locate clojure/contrib/math__init.class or clojure/contrib/math.clj on classpath: clojure.lang.RT.load (RT.java:443)
user>
最佳答案
这是一个正确配置的项目的示例,用于比较:
项目.clj:
(defproject math-example "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/math.numeric-tower "0.0.2"]])
src/math_example/core.clj:
(ns math-example.core
(:require [clojure.math.numeric-tower :as math]))
(def x (math/expt 2 10))
回复:
math-example.core> (math/expt 2 10)
1024
math-example.core> x
1024
math-example.core>
通常,使用大多数 clojure 库应该不会比添加依赖项和添加
:require
更难。标记到命名空间(如果您愿意,也可以使用 :use
标记)。
关于clojure - 如何在Clojure中使用expt函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19870495/