Import clojure.contrib.generic.math functions

I download clojure 1.2 and clojure -contrib-1.2.0.jar from the download site .

And I found information about math functions .

As the example shows, I tried to run the code.

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

But I got the following error when I run as follows.

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//205)
        ...
    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//172)
    ... 25 more

What could be wrong?

+3
source share
1 answer

Try :useinstead:require

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

Requiring makes the symbol (abs in this case) available, but you will have to fully qualify it. Use the import of the character in "your namespace":

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

Source: https://habr.com/ru/post/1760667/


All Articles