If you're curious to see alternatives, I wrote a basic dependency graph library based on Clojure's hierarchy implementation.
It's part of tools.namespace: https://github.com/clojure/tools.namespace/blob/tools.namespace-0.2.3/src/main/clojure/clojure/tools/namespace/dependency.clj Or also available standalone: https://github.com/stuartsierra/dependency -S On Friday, May 31, 2013 12:33:59 PM UTC-4, Alice 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 [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
