title: How can one create cyclic (and immutable) data structures in Clojure without extra indirection?
body: <p>I need to represent directed graphs in Clojure. I'd like to represent each node in the graph as an object (probably a record) that includes a field called <code>:edges</code> that is a collection of the nodes that are directly reachable from the current node. Hopefully it goes without saying, but I would like these graphs to be immutable.</p>
  
  <p>I can construct directed <em>acyclic</em> graphs with this approach as long as I do a topological sort and build each graph "from the leaves up".</p>
  
  <p>This approach doesn't work for cyclic graphs, however. The one workaround I can think of is to have a separate collection (probably a map or vector) of all of the edges for an entire graph. The <code>:edges</code> field in each node would then have the key (or index) into the graph's collection of edges. Adding this extra level of indirection works because I can create keys (or indexes) before the things they (will) refer to exist, but it feels like a kludge. Not only do I need to do an extra lookup whenever I want to visit a neighboring node, but I also have to pass around the global edges collection, which feels very clumsy. </p>
  
  <p>I've heard that some Lisps have a way of creating cyclic lists without resorting to mutation functions. Is there a way to create immutable cyclic data structures in Clojure?</p>