I want to compare two list in clojure,
(def a '(1 2 3 4 5))
(def b '(3 2 7 8 10))
make a result (2 3) or (3 2) by comparing elements of two lists.
(defn compareList[x, y]
(do
(def result '())
(def i 0)
(def j 0)
(while (< i 5)
(while (< j 5)
(if (= (nth x i) (nth y j))
(def result (conj (nth x i) result)))
(def j (inc j))
)
)
result))
(print (compareList a b))
it is my code. but result is (). where i mistake? help please.
Using a set would be more appropriate for your case
(clojure.set/intersection #{1 2 3 4 5} #{3 2 7 8 10})
That will output #{2 3}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With