tags:

views:

89

answers:

2

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")?

+7  A: 

Those are lists, not sets.

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

MayDaniel
Is there a list version of difference? Or do I need to roll my own?
JBristow
JBristow: No, but you can turn your list into a set: (clojure.set/difference (set '(1 2)) (set '(1 3))) => #{2}
j-g-faustus
+2  A: 

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}

bOR_