From 601a82e1ffce81288a07d5720e5287b48f1e822d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hol=C3=BD?= Date: Fri, 12 Jan 2024 11:11:24 +0100 Subject: [PATCH] Update 4-14_read-write-clojure-data-structures.asciidoc Suggest to prevent eliding data, explain why not to use str --- 04_local-io/4-14_read-write-clojure-data-structures.asciidoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/04_local-io/4-14_read-write-clojure-data-structures.asciidoc b/04_local-io/4-14_read-write-clojure-data-structures.asciidoc index a6052b3a..d84c5f65 100644 --- a/04_local-io/4-14_read-write-clojure-data-structures.asciidoc +++ b/04_local-io/4-14_read-write-clojure-data-structures.asciidoc @@ -16,6 +16,10 @@ Use +pr-str+ and +spit+ to serialize small amounts of data: (spit "data.clj" (pr-str [:a :b :c])) ---- +TIP: Wrap it with `+(binding [*print-length* nil, *print-level* nil] ...)+` to prevent eliding the data, especially when running from the REPL. + +NOTE: `pr-str` is more reliable than `str` for round-tripping data, especially if they use custom tagged literals or overide .toString (as java.util.HashMap does). + Use +read-string+ and +slurp+ to read small amounts of data: [source,clojure]