title: Common Lisp - Print on One Line / Return / Single Line Counter / Formatting
body: <p>I'm interested in implementing a "single line" counter / progress bar in Common Lisp. Nothing fancy, just something like: </p>
  
  <p>=></p>
  
  <p>==></p>
  
  <p>===>
  ... etc..</p>
  
  <p>And then have it start over again. Or maybe count the number of nodes I've visited.</p>
  
  <p>But, I want to do this all on one line, and clear the previously printed characters. For example, in Python, it would be something like:</p>
  
  <pre><code>for i in range(0,1000):    
      print "\r",i,"   "
  </code></pre>
  
  <p>Which would then count, but keep everything on a single line, while clearing everything printed on that line before any given iteration.</p>
  
  <p>I know in lisp there is <code>(format t "text" #\return)</code>, but that doesn't seem to work.</p>
  
  <p>Does anyone know how I might do this? (I've looked around and can't seem to find anything).</p>
  
  <p>Thanks,</p>
  
  <p>Andrew</p>
  
  <p><em><strong>EDIT:</em></strong></p>
  
  <p>I found the solution. You need to add a directive (the general-purpose "<code>~A</code>" worked) for the <code>#\return</code> to be processed:</p>
  
  <pre><code>(loop for i from 0 to 50000 do
          (format t "~A~A         " #\return i))
  </code></pre>
  
  <p>This will count to 50,000 and you can watch it do it. So, It'll work for any other situation you might want to reuse a single output line.</p>