I'm writing a clojure program which parses XML. As a part of this, I wish to create a tree of the nodes in the XML document, based on the clojure.xml/parse function. However I'd like the tree to be bi-directional - that is, each node has a list of children, and a pointer to its parent. There is only one problem: all data is immutable, and so I can't 'add' a pointer to the parent without changing the child, thus making the parent's pointer useless.
I've found this answer: How can one create cyclic (and immutable) data structures in Clojure without extra indirection?
The solution suggested there seems to be creating a separate index map, which refers to the objects inside. This seems like a huge amount of work for a much worse solution. I'd have no problem for the tree to be mutable during construction, however I can't figure out how can it be done. Is there really no way to get a cyclic pointer in clojure?
Thanks!