title: Explaining Lisp's dotimes: What is result-form doing?
body: <p>I'm looking at the LispWorks <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_dotime.htm" rel="nofollow noreferrer">Hyperspec</a> on <code>dotimes</code> but I don't understand what the third variable <code>[result-form]</code> is doing. The examples are as follows:</p>
  
  <pre><code>(dotimes (temp-one 10 temp-one)) =&gt;  10
  (setq temp-two 0) =&gt;  0
  (dotimes (temp-one 10 t) (incf temp-two)) =&gt;  T
  temp-two =&gt;  10
  </code></pre>
  
  <p>The Hyperspec says</p>
  
  <blockquote>
    <p>...Then result-form is evaluated. At the time result-form is
    processed, var is bound to the number of times the body was executed.</p>
  </blockquote>
  
  <p>Not sure what this is saying. Why is the third variable necessary in these two <code>dotimes</code> examples? I seem to be able to leave it out entirely in the second example and it works. My next example (not sure where I found it),</p>
  
  <pre><code>(defun thing (n)
      (let ((s 0))
        (dotimes (i n s)
          (incf s i))))
  </code></pre>
  
  <p>Puzzles me as well. What use is <code>s</code> serving?</p>