str生成一个包含其映射的字符串

时间:2014-04-12 10:52:58

标签: map clojure lazy-evaluation

当我在mapstr时,我得到clojure.lang.LazySeq的字符串化。

user=> (str (map inc (range 3)))
"clojure.lang.LazySeq@7861"

我找到并尝试了很多答案 - applydoalldoseq,不同的映射,映射使用doall的自定义函数和其他内容,尝试不同的repl等等 - 但在字符串化之前似乎无法将map变为eval。

更新:这也应该适用于str的更一般情况:

user=> (str "pre string " (map inc (range 3)) " post string")

期望的输出:

user=> "pre string 123 post string"

2 个答案:

答案 0 :(得分:1)

你需要这样的东西吗?

(apply str (map inc (range 3)))
=> "123"

向我们展示您想要的输出,以确保我们在同一页面上。

不过,我不知道你想要的输出是什么。

(str "pre string " (apply str (map inc (range 3))) " post string")
=> "pre string 123 post string"

答案 1 :(得分:1)

使用 seq

(str (seq (map inc (range 3))))
"(1 2 3)"