title: Closure - clarify variable and function
body: <p>In this example on Wikipedia (<a href="http://en.wikipedia.org/wiki/Closure_(computer_programming)" rel="nofollow">http://en.wikipedia.org/wiki/Closure_(computer_programming)</a> ) it claims that invoking the variable <code>closure1</code>  with <code>closure1(3)</code> will return <code>4</code>. Can someone walk through the example - I don't understand.</p>
  
  <pre><code>function startAt(x)
     function incrementBy(y)
         return x + y
     return incrementBy
  
  variable closure1 = startAt(1)
  variable closure2 = startAt(5)
  
  Invoking the variable closure1 (which is of function type) with closure1(3) will return 4, while invoking closure2(3) will return 8. While closure1 and closure2 are both references to the function incrementBy, the associated environment will bind the identifier x to two distinct variables in the two invocations, leading to different results.
  </code></pre>
  
  <p>If it helps, here's my current understanding. <code>variable closure1 = startAt(1)</code> sets the variable <code>closure1</code> to the function <code>startAt()</code> which by default is initialized to <code>1</code>. However, invoking <code>closure1(3)</code> sets this default value to <code>3</code>. What I don't understand then is where does <code>y</code> come from.</p>
  
  <pre><code>variable closure1 = startAt(1)
  </code></pre>