title: Explain a lazy evaluation quirk
body: <p>I am reading Hadley Wickhams's book on Github, in particular <a href="http://adv-r.had.co.nz/Functions.html#lazy-evaluation" rel="noreferrer">this part on lazy evaluation</a>. There he gives an example of consequences of lazy evaluation, in the part with <code>add/adders</code> functions. Let me quote that bit: </p>
  
  <blockquote>
    <p>This [lazy evaluation] is important when creating closures with lapply or a loop:</p>
  
  <pre><code>add &lt;- function(x) {
    function(y) x + y
  }
  adders &lt;- lapply(1:10, add)
  adders[[1]](10)
  adders[[10]](10)
  </code></pre>
    
    <p>x is lazily evaluated the first time that you call one of the adder
    functions. At this point, the loop is complete and the final value of
    x is 10. Therefore all of the adder functions will add 10 on to their
    input, probably not what you wanted! Manually forcing evaluation fixes
    the problem:</p>
  
  <pre><code>add &lt;- function(x) {
    force(x)
    function(y) x + y
  }
  adders2 &lt;- lapply(1:10, add)
  adders2[[1]](10)
  adders2[[10]](10)
  </code></pre>
  </blockquote>
  
  <p>I do not seem to understand that bit, and the explanation there is minimal. Could someone please elaborate that particular example, and explain what happens there? I am specifically puzzled by the sentence "at this point, the loop is complete and the final value of x is 10". What loop? What final value, where? Must be something simple I am missing, but I just don't see it. Thanks a lot in advance.</p>