title: Clojure printing lazy sequence
body: <p>I'm trying to print out my binary tree but Clojure is giving me a hard time printing out the sequences properly.</p>
  
  <p>So, I have a list of nodes <code>'(1 2 3)</code> for example.</p>
  
  <p>In each iteration I want to print out the node with a number of spaces before and after each element.</p>
  
  <pre><code>(defn spaces [n]
    (apply str (repeat n " ")))
  </code></pre>
  
  <p>Great, this seems to work.</p>
  
  <p>So, suppose I have a list of <code>nodes</code> <code>'(:a :b :c)</code> I want to print out on one line, with as said, the spaces.</p>
  
  <pre><code>(println (map #(str (spaces before) % (spaces (dec before))) nodes))
  </code></pre>
  
  <p>I have a list of items. Using the map I get a list of string objects. Great, so I can print them!</p>
  
  <p>But this gives me this:</p>
  
  <pre><code>(clojure.lang.LazySeq@d0b37c31 clojure.lang.LazySeq@105879a9 clojure.lang.LazySeq@8de18242)
  </code></pre>
  
  <p>So I googled how to print lazy sequences and I came around to using <code>print-str</code> command. According to the docs this prints to a string which then gets returned.</p>
  
  <pre><code>(println (print-str (map #(str (spaces before) % (spaces (dec before))) nodes)))
  </code></pre>
  
  <p>But this gives me this:</p>
  
  <pre><code>(clojure.lang.LazySeq@d0b37c31 clojure.lang.LazySeq@105879a9 clojure.lang.LazySeq@8de18242)
  </code></pre>
  
  <p>No change.. Hrm. Any help is greatly appreciated.</p>