You can express the algorithm using reduce with the set as an accumulator. Also, consider: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L4969 and related hierarchy functions.
On Fri, May 31, 2013 at 12:33 PM, Alice <dofflt...@gmail.com> wrote: > (def graph > {"a" {:dependencies ["b" "d"]} > "b" {:dependencies ["c" "e"]} > "c" {:dependencies ["d" "e"]} > "d" {:dependencies []} > "e" {:dependencies []}}) > > (defn resolve-dep > [graph name] > (let [resolved (atom []) > resolved-set (atom #{}) > f (fn f [name] > (doseq [x (:dependencies (graph name))] > (f x)) > (when-not (@resolved-set name) > (swap! resolved conj name) > (swap! resolved-set conj name)))] > (f name) > @resolved)) > > (resolve-dep graph "a") > ;=> ["d" "e" "c" "b" "a"] > > This code works, but not sure if it's idiomatic clojure code. > The use of atom feels like procedural than functional to me since > there's no concurrency involved at all. > > Any suggestions? > > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.