Last active
June 29, 2022 21:09
-
-
Save 28/b6b94f84a38867339e6ba84d00fd8ca2 to your computer and use it in GitHub Desktop.
A simple way to pretty print Clojure data/code to a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.pprint :as pp] | |
'[clojure.edn :as edn]) | |
(def collection-to-print {:a 1 | |
:b 2 | |
:c 3 | |
:d [1 2 3 4 5]}) | |
(defn pretty-spit | |
[file-name collection] | |
(spit (java.io.File. file-name) | |
(with-out-str (pp/write collection :dispatch pp/code-dispatch)))) | |
;; write to EDN file | |
(pretty-spit "test.edn" collection-to-print) | |
;; try to read written file | |
(edn/read-string (slurp "test.edn")) |
Hi,
It seems that the snippet was not functional at all. :-D
I have rewrotten it a bit and added a part with edn/read-string.
Cheers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
trying to read this using edn/read-string fails fwiw.