Hi Colin,

Sorry, a bit late to the party here, but it might be worth taking a look at 
Jeffrey 
Straszheim's c.c.graph library to see one way of modeling DAG's and 
implementing various graph operations (such as topological sort and 
computing strongly connected components) in Clojure:

API: http://clojure.github.com/clojure-contrib/graph-api.html
Source: 
https://github.com/clojure/clojure-contrib/blob/master/modules/graph/src/main/clojure/clojure/contrib/graph.clj

Note that in the library, graphs are represented by a directed-graph struct 
(defined at the top of the source file) with two fields:

- nodes: a collection of the nodes in the graph
- neighbors: a function that takes a node and returns a collection of that 
node's neighbors

Since Clojure maps are also functions that will return the value associated 
with a key when called with the key, neighbors can simply be a map of nodes 
to collections of neighbors.

records are now recommended over structs, so it may be better to define a 
directed-graph record:

  (defrecord directed-graph [nodes neighbors])

A graph (for example, a graph of two nodes :a and :b that are connected to 
each other) can then created via:

  (def my-graph (directed-graph. [:a :b] {:a [:b], :b [:a]}))

records can be used in exactly the same way as structs, so this can be used 
right away with all the functions defined in the library.

Hope this helps!

-- 
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

Reply via email to