I'm trying to implement bubble sort function in clojure,
Below b_sort function gives error,
But if I execute statements inside b_sort function it works,
(def r_list (take 10 (repeatedly #(rand-int 100))))
(def r_vec (vec r_list))
(def cnt (count r_vec))
(defn b_sort
(loop [i 0]
(if (< i cnt)
(loop [j (+ i 1)]
(if (< j cnt)
(do
(def a (r_vec i))
(def b (r_vec j))
(if (> a b)
(do
(def r_vec (assoc r_vec i b j a))
(println r_vec)
)
)
(if (< j cnt)
(recur (inc j)
)))
)
)
)
(if (< i cnt)
(recur (inc i)
)
)
)
)
Below is the error in b_sort function,
(if (< i cnt) (recur (inc i))))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ should satisfy vector? or value (... (loop ... ... ...)) ^^^^ should satisfy vector?
Actually there was no arguments in the defn
statement,
When I changed the statement to (defn b_sort []
it worked.