How do I make a string from a lazy sequence in a clojure?

I use str to build strings all the time:

user> (str '(1 2 3) " == " '(1 2 3))
"(1 2 3) == (1 2 3)"

      

and about once a day I will be bitten on the ass:

user> (str '(1 2 3) " == " (map identity '(1 2 3)))
"(1 2 3) == clojure.lang.LazySeq@7861"

      

I guess I can say:

user> (with-out-str (print '(1 2 3) " == " (map identity '(1 2 3))))
"(1 2 3)  ==  (1 2 3)"

      

instead, but seems ugly. Is there a better way?

+3


source to share


2 answers


You can use print-str

:



(print-str '(1 2 3) " == " (map identity '(1 2 3)))
;; => "(1 2 3) == (1 2 3)"

      

+4


source


You can turn a LazySeq object into a Cons Cons with seq

:



user=> (str '(1 2 3) " == " (map identity '(1 2 3)))
"(1 2 3) == clojure.lang.LazySeq@7861"

user=> (str '(1 2 3) " == " (seq (map identity '(1 2 3))))
"(1 2 3) == (1 2 3)"

      

+1


source







All Articles