I am reading the Clojure section of the book Seven Languages in Seven Weeks. It says:
You can merge two sets, like this:
user=> (clojure.set/union #{:skywalker} #{:vader})
#{:skywalker :vader}
Or compute the difference:
(clojure.set/difference #{1 2 3} #{2})
This doesn't work on my version (Clojure 1.7.0
and Java version"1.8.0_51"
):
user=> (clojure.set/difference #{1 2 3} #{4})
ClassNotFoundException clojure.set java.net.URLClassLoader.findClass (:-1)
user=> (clojure.set/union #{:skywalker} #{:vader})
ClassNotFoundException clojure.set java.net.URLClassLoader.findClass (:-1)
In Clojuredocs shorter function names are used in the examples, but that also doesn't work:
user=> (difference #{1 2} #{2 3})
CompilerException java.lang.RuntimeException: Unable to resolve symbol: difference in this context, compiling:(NO_SOURCE_PATH:14:1)
Why am I receiving these errors and how should I fix that?
Namespaces other than clojure.core
and user
are only loaded if someone loads them. The standard way to load a namespace is with require
.
(require '[clojure.set :as set])
(set/union ...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With