Jon Bristow
Jon Bristow

Reputation: 1735

How do I use clojure.set/difference? Why won't it work on a PersistentSet?

The following code:

(require '[clojure.set])
(println (clojure.set/difference '("a" "b" "c" "d") '("c" "d" "e" "f")))

gives me the following error:

java.lang.ClassCastException: clojure.lang.PersistentList (repl-1:47)

I don't understand what I'm doing wrong. Shouldn't this print out ("a" "b")?

Upvotes: 5

Views: 3625

Answers (2)

bOR_
bOR_

Reputation: 381

I think you don't need to require '[clojure.set]. It seems to be automatically loaded with core. Just starting a repl, and typing the below works (at least for me).

user=> (clojure.set/difference (set '(1 2 3)) (set '(3 4 5)))

\#{1 2}

Upvotes: 4

MayDaniel
MayDaniel

Reputation: 1484

Those are lists, not sets.

(println (clojure.set/difference #{"a" "b" "c" "d"} #{"c" "d" "e" "f"}))

Upvotes: 15

Related Questions