2010-08-20 62 views
3

我從download site下載clojure 1.2和clojure-contrib-1.2.0.jar。導入clojure.contrib.generic.math-functions

我找到了關於math functions的信息。

正如示例中所示,我試圖運行代碼。

(ns your-namespace 
    (:require clojure.contrib.generic.math-functions)) 
(println (abs 10)) 

但是,我得到以下錯誤,當我運行如下。

CLOJURE_JAR=/Users/smcho/bin/jar/clojure.jar:/Users/smcho/bin/jar/clojure-contrib-1.2.0.jar 
java -cp $CLOJURE_JAR:$CLASSPATH clojure.main SOURCE.CLJ 
 
Exception in thread "main" java.lang.Exception: Unable to resolve symbol: abs in this context (hello.clj:4) 
    at clojure.lang.Compiler.analyze(Compiler.java:5205) 
     ... 
    at clojure.main.main(main.java:37) 
Caused by: java.lang.Exception: Unable to resolve symbol: abs in this context 
    at clojure.lang.Compiler.resolveIn(Compiler.java:5677) 
    at clojure.lang.Compiler.resolve(Compiler.java:5621) 
    at clojure.lang.Compiler.analyzeSymbol(Compiler.java:5584) 
    at clojure.lang.Compiler.analyze(Compiler.java:5172) 
    ... 25 more 

可能是什麼問題?

+1

根據您確切的需要,clojure.contrib.math可能更可取。 – 2010-08-20 03:03:14

回答

6

嘗試的:use代替:require

(ns your-namespace 
    (:use clojure.contrib.generic.math-functions)) 
(println (abs 10)) 
10 
nil 

要求使得符號(在這種情況下ABS)可用的,但你必須完全限定它。使用將符號導入到「your-namespace」中:

(ns your-namespace2 
    (:require clojure.contrib.generic.math-functions)) 
(println (clojure.contrib.generic.math-functions/abs 10)) 
10 
nil 
+0

':require ...:參考:all'現在優先於':use'用於Clojure 1.4.0+庫 - 請參閱:http://dev.clojure.org/display/community/Library+Coding+Standards& https://github.com/bbatsov/clojure-style-guide – omiel 2014-01-16 13:15:33