我想比较一下clojure中的两个列表,
(def a '(1 2 3 4 5))
(def b '(3 2 7 8 10))
Run Code Online (Sandbox Code Playgroud)
通过比较两个列表的元素来得到结果(2 3)或(3 2).
(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))
Run Code Online (Sandbox Code Playgroud)
这是我的代码.但结果是().哪里弄错了?请帮忙.