Skip to content

Instantly share code, notes, and snippets.

@raek
Created October 1, 2010 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/606840 to your computer and use it in GitHub Desktop.
Save raek/606840 to your computer and use it in GitHub Desktop.
(defn file-stored
"Creates an instance of ref-type with its value loaded from, and on changes
automatically stored in the file with the filename."
[ref-type filename]
(let [r (ref-type (read-string (slurp filename)))]
(add-watch r ::file-stored #(spit filename (pr-str %4)))
r))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment