Search code examples
mathclojure

Using clojure.math.numeric-tower, or any library


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?


Solution

  • 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!