Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将大型数据结构作为EDN写入clojure中的磁盘_Clojure_Edn - Fatal编程技术网

将大型数据结构作为EDN写入clojure中的磁盘

将大型数据结构作为EDN写入clojure中的磁盘,clojure,edn,Clojure,Edn,在Clojure中将数据结构写入磁盘,以便使用edn/read将其读回的最惯用方法是什么?我按照中的建议尝试了以下方法: 但是,这将只写入前100项,然后是“…”。我也尝试了(prn(doall-large-data-structure)),得到了同样的结果 我用(doseq[I large data structure](pr I))一行一行地写,但是我必须在序列的开头和结尾手动添加参数,以获得所需的结果。您可以控制通过 考虑使用,而不是手动打开写入器,而不是手动绑定到 *out * (b

在Clojure中将数据结构写入磁盘,以便使用edn/read将其读回的最惯用方法是什么?我按照中的建议尝试了以下方法:

但是,这将只写入前100项,然后是“…”。我也尝试了
(prn(doall-large-data-structure))
,得到了同样的结果


我用
(doseq[I large data structure](pr I))
一行一行地写,但是我必须在序列的开头和结尾手动添加参数,以获得所需的结果。

您可以控制通过

考虑使用,而不是手动打开写入器,而不是手动绑定到<代码> *out *

(binding [*print-length* false]
  (spit "data.clj" (pr-str large-data-structure))

根据评论编辑:

(with-open [w (clojure.java.io/writer "data.clj")]
  (binding [*print-length* false
            *out* w]
    (pr large-data-structure)))

注意
*print length*
的根绑定为
nil
,因此在上面的示例中不需要绑定它。我会在您最初的
pr
调用时检查当前绑定。

使用
(pr str)
对于大型数据结构来说是个坏主意;它将把它打印成内存中的字符串,这可能比原始结构占用更多内存。我只需将
*print length*
nil绑定添加到OP代码中的绑定向量中。我的
*print length*
设置为100。罪魁祸首似乎是emacs live。看见
(with-open [w (clojure.java.io/writer "data.clj")]
  (binding [*print-length* false
            *out* w]
    (pr large-data-structure)))