Some Practical Clojure Examples
← prev | next →     Top-level ToC     /save-and-load-state.html     (printable version)

From Brandon Bloom’s blog post:

(def db (atom {...}))

(defn save-data []
  (spit "program-state.txt" (prn-str @db)))

(defn load-data []
  (reset! db (read-string (slurp "program-state.txt"))))