This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
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?You need to require the namespace before you can use it
(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 java.net.URLClassLoader/findClass (URLClassLoader.java:445).
clojure.set
doesn't work in the repl but evaluate inside emacs work without explicit require
CIDER probably requires them during start up, so they have been already required
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.
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]`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)
The example shows a way to declare a function that can be called passing 1 parameter or 2 parameters.
@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