导入clojure.contrib.generic.math-函数

pro*_*eek 3 namespaces clojure require

我从下载站点下载了clojure 1.2和clojure-contrib-1.2.0.jar .

我找到了有关数学函数的信息.

如示例中所示,我尝试运行代码.

(ns your-namespace
  (:require clojure.contrib.generic.math-functions))
(println (abs 10))
Run Code Online (Sandbox Code Playgroud)

但是,当我运行如下时,我得到以下错误.

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
Run Code Online (Sandbox Code Playgroud)
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

可能有什么问题?

G__*_*G__ 6

尝试:use而不是:require

(ns your-namespace
  (:use clojure.contrib.generic.math-functions))
(println (abs 10))
10
nil
Run Code Online (Sandbox Code Playgroud)

要求使符号(在这种情况下为abs)可用,但您必须完全符合它.使用将符号导入"your-namespace":

(ns your-namespace2
  (:require clojure.contrib.generic.math-functions))
(println (clojure.contrib.generic.math-functions/abs 10))
10
nil
Run Code Online (Sandbox Code Playgroud)