Closures/Value capture: Difference between revisions

Content added Content deleted
(add scala)
Line 635: Line 635:


With Ruby 1.9, ''i'' is always local to its block. With Ruby 1.8, ''i'' is local unless there is another ''i'' in the outer scope. If ''i'' is not local, all 10 procs will return 100.
With Ruby 1.9, ''i'' is always local to its block. With Ruby 1.8, ''i'' is local unless there is another ''i'' in the outer scope. If ''i'' is not local, all 10 procs will return 100.

=={{header|Scala}}==
<lang scala>val closures=for(i <- 0 to 9) yield (()=>i*i)
0 to 8 foreach (i=> println(closures(i)()))</lang>
Output:
<pre>0
1
4
9
16
25
36
49
64</pre>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==