Union and set difference in Clojure

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 in 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 Examples Use shorter names of functions, but it also does not 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 getting these errors and how can I fix it?

+3


source to share


1 answer


Namespaces other than clojure.core

and user

are loaded only if someone else loads them. The standard way to load a namespace is require

.



(require '[clojure.set :as set])

(set/union ...)

      

+5


source







All Articles