Fork me on GitHub
#beginners
<
2022-07-16
>
Lukas10:07:04

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).
clojure.math
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)

Lukas10:07:19

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

Lukas10:07:19

(clojure.set/intersection #{1 3} #{1 2})
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:445).
clojure.set
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
pavlosmelissinos11:07:35

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.

Lukas11:07:48

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)
     vec   
     (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.flexiana16: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.flexiana16: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
kennytilton04:07:21

@U03P73HRDSR wrote: "The math and recursion piece I understand..." The missing piece may be multi-arity functions: https://clojure.org/guides/learn/functions#_multi_arity_functions