Fork me on GitHub

Hey, I'm trying to use clojure.math but I get a ClassNotFoundException

Clojure 1.11.1
user=> clojure.math/E
Syntax error (ClassNotFoundException) compiling at (REPL:0:0).
what am I doing wrong here?

Alex Miller (Clojure team)10:07:23

You need to require the namespace before you can use it

Alex Miller (Clojure team)10:07:10

(require ‘clojure.math)


ty, is this always the case? I think i sometimes use clojure.pprint or clojure.set without requiring the ns


(clojure.set/intersection #{1 3} #{1 2})
Execution error (ClassNotFoundException) at (
doesn't work in the repl but evaluate inside emacs work without explicit require

Ben Sless11:07:31

CIDER probably requires them during start up, so they have been already required

👍 1

Also if you're lucky and one of your requires has already loaded clojure.math or clojure.set then yes, you won't have to require those as well but it's not a good idea to depend on this. You should be explicit about your dependencies.


thanks a lot for clearifying this for me, really appreciate that

Scott Elliott16:07:18

I'm trying to figure out/practicing how to write a function that will append to a vector. I've been studying the following example of the Fibonacci Sequence.

(defn fib-seq
  ([n] (fib-seq n [1 1])) 
  ([n vec]    
   (if (> (count vec) n)
     (recur n (conj vec (+ (nth vec (- (count vec) 2)) (last vec)))))))
The math and recursion piece I understand, but I'm failing to understand when the vector is created/if it has to be created before something can be append/conj to it. What is going on here in line 3?`([n vec]`

Daniel Vieira16:07:32

If the user calls (fib-seq 3) then the vec will be [1 1], meaning it will call (fib-seq 3 [1 1]) internally. The user has the opinion to call (fib-seq n) or (fib-seq n vec)

Daniel Vieira16:07:21

The example shows a way to declare a function that can be called passing 1 parameter or 2 parameters.

Scott Elliott16:07:52

Thank you

👍 1

@U03P73HRDSR wrote: "The math and recursion piece I understand..." The missing piece may be multi-arity functions: