[英]How to use expt function in Clojure?
我試圖根據這個答案使用expt
函數但是當我嘗試在REPL中(use 'clojure.math.numeric-tower)
我得到了錯誤
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)
我想我需要把Leiningen的依賴信息放在這里解釋
[org.clojure/math.numeric-tower "0.0.2"]
在我的project.clj
,我做到了,但我仍然得到同樣的錯誤。 我究竟做錯了什么?
編輯
在這個答案中,我去了我的項目目錄並做了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中得到同樣的錯誤。
EDIT2
根據Vidya的回答,我試圖使用石榴,但沒有成功。 這是我試過的。 我究竟做錯了什么:
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>
以下是與以下內容進行比較的正確配置項目的示例:
project.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))
REPL:
math-example.core> (math/expt 2 10)
1024
math-example.core> x
1024
math-example.core>
一般而言,使用大多數clojure庫並不比添加依賴項和向命名空間添加:require
標記(或者如果您願意, :use
標記)更難。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.