gpt4 book ai didi

clojure - 如何在Clojure中将PersistentHashMap漂亮地打印为字符串?

转载 作者:行者123 更新时间:2023-12-03 09:00:13 25 4
gpt4 key购买 nike

如何在Clojure中将PersistentHashMap漂亮地打印为字符串?我正在寻找类似的东西:

(str (pprint {... hash map here...})

我可以以字符串形式传递

最佳答案

user=> (import java.io.StringWriter)
java.io.StringWriter
user=> (use '[clojure.pprint :only (pprint)])
nil
user=> (defn hashmap-to-string [m]
(let [w (StringWriter.)] (pprint m w)(.toString w)))
#'user/hashmap-to-string
user=> (hashmap-to-string {:a 1 :b 2})
"{:a 1, :b 2}\n"

关于clojure - 如何在Clojure中将PersistentHashMap漂亮地打印为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4555496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com