Writing large map into a file

I’m trying to write large map into a file, and for some reason it doesn’t save the whole thing. It writes a map that ends with ellipsis like that {:key-n val-n, ...}. I tried switching from spit to doing this:

(with-open [w (clojure.java.io/writer filename)]
      (binding [*out* w] (pr my-large-map)))

Yet that didn’t help. What am I missing? I mean the map is not that big, it actually contains less than 200 elements, but the keys are very long strings. Could that be some kind repl/nrepl/CIDER limitation?

It seems due to *print-length* limitation. I think CIDER makes it 100 by default.

Clojure defaults to no limit. So this will work as normal outside of Cider.

I opened an issue recently on Cider: https://github.com/clojure-emacs/cider/issues/2507 for this.

Out of curiosity: why not just use spit and pr-str?

Seems it was too see if spit was the problem.

1 Like

Out of curiosity: why not just use spit and pr-str ?

pr-str will materialize a java.lang.String buffer containing the entire contents of the file eagerly. pr or prn however just streams writes to a writer, which lets you bypass the buffer and go “straight” to the disk. It’s just a memory/IO optimization that can be relevant for “lots” of data.


Good point about eagerness vs. streaming.

Also I should have properly read the first post, the OP explicitly mentioned they switched from spit:man_facepalming:

1 Like
(binding [*print-length* nil]
  ;; do all your spits here...
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.