I try to learn a bit of Clojure because the language looks nice. But it seems that there is no info anywhere on how to install/use libraries like for example the clojure.math.numeric-tower.
For now I run the REPL by typing this in my Linux shell:
java -cp ~/Clojure/clojure-1.3.0/clojure-1.3.0.jar clojure.main
I downloaded the numeric-tower jar, and put it everywhere. I have modified the -cp option in every possible way. I have put the numeric_tower.clj file everywhere. It still doesn't work.
What's the way to use the libraries?
I had this same issue yesterday (also as a newcomer to Clojure). From my understanding, between Clojure 1.2 and 1.3 they split out many of the contrib libraries into separate projects so that they could be managed more easily. And shrink the core of what Clojure is.
The easiest way to accomplish what you're trying to do is through leiningen (I got this answer from technomancy in the #clojure IRC channel yesterday evening). The recommendation is to create a "playground" project using leiningen that you can play around in and learn Clojure.
So, create a playground project with:
lein new playground
Modify the project.clj file to include:
[org.clojure/math.numeric-tower "0.0.1"]
as a dependency. I was told that http://search.maven.org/ is the easiest way to find out which is the most up-to-date version of a particular library.
Then, run
lein deps
to pull in the jars. Now you're ready to
lein repl
to get going.
Once the repl is started, pull in numeric-tower:
(require '[clojure.math.numeric-tower :as math])
Then you can do your expt call:
(math/expt 4 6) ;; yields 4096
Hope that helps!
Thanks to all. It works now. In fact the problem that really confused me was that java didn't understand the ~ (linux home) symbol after a colon in the classpath. I was doing
java -cp ~/Clojure/clojure-1.3.0/clojure-1.3.0.jar:~/Clojure/lib clojure.main
and java doesn't understand that.
However, if you do
java -cp ~/Clojure/clojure-1.3.0/clojure-1.3.0.jar:/home/username/Clojure/lib clojure.main
it works.
Strange behavior of the classpath variable.
I would have used lein, but since I'm considering doing some programming for android, I thought it would be better if I could understand how all this work with java only. Unless lein can package android project as well?
Anyway, thanks. All three replies were very informative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With