4

I am trying to use expt function according to this answer but when I try to do (use 'clojure.math.numeric-tower) in REPL I get the error

user> (use 'clojure.math.numeric-tower)
(use 'clojure.math.numeric-tower)FileNotFoundException Could not locate clojure/math/numeric_tower__init.class or clojure/math/numeric_tower.clj on classpath:   clojure.lang.RT.load (RT.java:443)

I thought I needed to put Leiningen dependency information as explained here

[org.clojure/math.numeric-tower "0.0.2"]

in my project.clj, and I did that but I still get the same error. What am I doing wrong?


EDIT

As in this answer I went to my project directory and did lein deps

a@b:~/command-line-args$ lein deps
Retrieving org/clojure/math.numeric-tower/0.0.2/math.numeric-tower-0.0.2.pom from central
Retrieving org/clojure/math.numeric-tower/0.0.2/math.numeric-tower-0.0.2.jar from central
a@b:~/command-line-args$ 

but I still get the same error in REPL.


Edit2

As per Vidya's answer I am trying to use Pomegranate but without success. This is what I tried. What am I doing wrong:

user> (use '[cemerick.pomegranate :only (add-dependencies)])
nil
user> (add-dependencies :coordinate '[[org.clojure/math.numeric-tower "0.0.2"]]
                        :repositories (merge cemerick.pomegranate.aether/maven-central
                                             {"clojars" "http://clojars.org/repo"}))
{}
user> (require '(numeric-tower core stats charts))
FileNotFoundException Could not locate numeric_tower/core__init.class or numeric_tower/core.clj on classpath:   clojure.lang.RT.load (RT.java:443)
user> (require 'clojure.contrib.math)
FileNotFoundException Could not locate clojure/contrib/math__init.class or clojure/contrib/math.clj on classpath:   clojure.lang.RT.load (RT.java:443)
user> 
Community
  • 1
  • 1
Zeynel
  • 13,145
  • 31
  • 100
  • 145
  • 1
    did you restart your repl after changing your deps? deps are only found at startup time – noisesmith Nov 08 '13 at 23:51
  • 1
    Everything looks fine. Have you also restarted your REPL? – Leon Grapenthin Nov 08 '13 at 23:53
  • Yes, I restarted the REPL. – Zeynel Nov 09 '13 at 00:02
  • And I did `lein deps` in my project directory and I still get the same error in REPL (See the edit to my question). – Zeynel Nov 09 '13 at 00:16
  • 1
    Did you execute lein repl from the project directory? – Leon Grapenthin Nov 09 '13 at 00:52
  • No, I was trying to do this in REPL in emacs. I did in leiningen REPL and it worked. How do I use this library in emacs REPL? I opened a clojure file in `/src` and I did `C-c C-k` and then `C-c M-n` and tried to get the library, but it did not work. – Zeynel Nov 09 '13 at 01:15
  • It's important that you invoke the M-x nrepl-jack-in when a buffer is open that is part of the project. Either a dired buffer of the project folder with the project.clj in it or any file within that folder or subfolders. (Edit: The keys you mentioned for compiling and switching the namespace should work on any source file that is part of the project and compiles flawlessly.) – Leon Grapenthin Nov 09 '13 at 03:16

1 Answers1

5

here is an example of a properly configured project to compare with:

project.clj:

(defproject math-example "0.1.0-SNAPSHOT"                            
  :description "FIXME: write description"                            
  :url "http://example.com/FIXME"                                    
  :license {:name "Eclipse Public License"                           
            :url "http://www.eclipse.org/legal/epl-v10.html"}        
  :dependencies [[org.clojure/clojure "1.5.1"]                       
                 [org.clojure/math.numeric-tower "0.0.2"]]) 

src/math_example/core.clj:

(ns math-example.core                                                
  (:require [clojure.math.numeric-tower :as math]))                  

(def x (math/expt 2 10)) 

repl:

math-example.core> (math/expt 2 10)                                  
1024                                                                 
math-example.core> x                                                 
1024                                                                 
math-example.core> 

Using most clojure libraries should, in general, be no harder than adding the dependency and adding a :require tag to a namespace (or a :use tag if you prefer).

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
  • Great, thanks. This works. The only thing I don't understand is the `#`. When I enter that I get an error. I used the instructions here http://clojure-doc.org/articles/tutorials/emacs.html#using-the-repl to get the namespace to REPL – Zeynel Nov 09 '13 at 02:35
  • that was printed when I hit ctrl-c alt-n from emacs to switch the repl to that namespace. I didn't actually type it. the equivalent would have been (in-ns 'math-example.core). I have deleted it from the answer. – Arthur Ulfeldt Nov 09 '13 at 03:00