Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

set

clojure

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

like image 302
Jon Bristow Avatar asked Jul 06 '10 20:07

Jon Bristow


2 Answers

Those are lists, not sets.

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

like image 199
MayDaniel Avatar answered Nov 07 '22 13:11

MayDaniel


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}
like image 37
bOR_ Avatar answered Nov 07 '22 13:11

bOR_