Print a lazy seq
To get a str
representation of a non-lazy collection is not an issue:
(str (mapv inc (range 10)))
;; => "[1 2 3 4 5 6 7 8 9 10]"
But for lazy seqs str
does evaluate the sequence (Achtung with infinite sequences!) but we get the object representation:
(str (map inc (range 10)))
;; => "clojure.lang.LazySeq@c5d38b66"
We can use pr-str
for lazy seqs:
(pr-str (map inc (range 10)))
;; => "(1 2 3 4 5 6 7 8 9 10)"
For printing with print
or println
this is not necessary:
(println (map inc (range 10)))
;; (1 2 3 4 5 6 7 8 9 10)
;; => nil
But it is for printf
:
(printf "This is a lazy seq: %s\n" (map inc (range 10)))
;; This is a lazy seq: clojure.lang.LazySeq@c5d38b66
;; => nil
(printf "This is a lazy seq: %s\n" (pr-str (map inc (range 10))))
;; This is a lazy seq: (1 2 3 4 5 6 7 8 9 10)
;; => nil