10

How can I use clojure.set in ClojureScript?

I always get a error.

(def middle-land (set (for [x water-hor
                            y (vec (clojure.set/difference (set (range 0 board-side))
                                                           (set water-ver)))]
                    [x y])))

ReferenceError: clojure is not defined

1 Answer 1

18

Seems you need to explicitly require the namespace to be able to use it:

ClojureScript:cljs.user> (ns core (:require clojure.set))
ClojureScript:core> (clojure.set/difference #{1 2} #{1 4}) ;=> #{2}
Sign up to request clarification or add additional context in comments.

5 Comments

You need to explicitly include clojure.set in Clojure as well.
@dnolen, is it some Leiningen "magic" that enables me to do this with plain Clojure then?
@dnolen Why does this clojure.set/difference work in clojure and not in clojurescript? I just copied the code over.
@ponzao yes Leiningen adds some namespaces to their REPL for convenience.
@dnolen, thanks for the clarification. Based on a quick experiment Leiningen seems to do this for other "goals" as well (lein midje worked without an explicit require also`).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.