Serialize persistent data structures in clojure

We all know that Rich uses the perfect tree-based hash method to implement persistent data structures in Clojure. This structure allows us to manipulate persistent data structures without much copying.

But it looks like I can't find the right way to serialize this particular structure. For instance:

(def foo {:a :b :c :d})
(def bar (assoc foo :e :f))
(def bunny {:foo foo :bar bar})

My question is:

How can I serialize bunnyso that the content foo, i.e. did :amatching with :band :cmapping to :dappear only once in serialized content? This is similar to resetting the memory image of structures. It also looks like the serialization of the “internal nodes” as well as the “leaf nodes” referred to here .

PS In case this matters, I create a large DAG (directed acyclic graph), where we are assocpretty little to associate these nodes with these nodes and want to serialize the DAG for subsequent de-serialization. The extended graph representation (i.e., the content that will be obtained when printing DAG in repl) is unacceptably longer.

+4
source share
2 answers

Davyzhu,

A few things first:

  • DAG, without a tokenization strategy, will be until DAG. If fooreferenced 1 or more times, each of them will be fully implemented (i.e. Displayed) in turn during printing. A.
  • ( ) . , , , (, ), /. , , , .
  • Clojure meta, , , DAG , .

:: , , DAG.

:

(def node1 {:a :b :c :d})
(def node2 {:e :f})
(def dictionary {:foo node1 :bar node2})

(def DAG [:bunny [:foo :bar]])

(println DAG) ; => [:bunny [:foo :bar]]

(defn expand-dag1
  [x]
  (if (keyword? x)
    (get dictionary x x)
    x))

(println (w/postwalk expand-dag1 DAG)) ; => [:bunny [{:a :b, :c :d} {:e :f}]]

. , , .. DAG .

+1

( Clojurescript, ) , .

, , foo (def bunny {:foo foo :bar bar}) "" , "" (def foo..) , foo .

  • , , ( , , .), bunny, . eval. , , , , .

  • "" , foo bar, bunny , - , . , , .

, , , 1. , , , , 2 , .

- , 1. , lisp, , .

+1

All Articles