I've created a non-recursive dfs implementation in Clojure. I'm using the wikipedia article on dfs as a guide. I'm very new to Clojure and functional programming in general. Any tips to improve readability, make the code more idiomatic, or improve performance would be very helpful. I'm aware there is already question about a recursive dfs implementation in Clojure, but I feel like this code is different enough to warrant a separate post.
(def graph {'a '(b c e) 'b '(a d f) 'c '(a g) 'd '(b) 'e '(a f) 'f '(b e)})
(defn label
[v discovered]
(cons v discovered))
(defn get-edges
[g v]
(get g v))
(defn labeled?
[v discovered]
(cond
(some #(= v %) discovered) true
:else false))
(defn build-stack
[S edges]
(concat S edges))
(defn dfs
[g v]
(loop
[discovered '() S (cons v ())]
(cond
(empty? S) (reverse discovered)
(labeled? (last S) discovered) (recur discovered (butlast S))
:else
(recur
(label (last S) discovered)
(build-stack (butlast S) (get-edges g (last S)))))))