Anonymous user
Closures/Value capture: Difference between revisions
→{{header|Groovy}}: new solution
m (→Function image copying approach: just a typo) |
(→{{header|Groovy}}: new solution) |
||
Line 278:
func #3: 9
</pre>
=={{header|Groovy}}==
Solution:
<lang groovy>def closures = (0..9).collect{ i -> { -> i*i } }</lang>
Test:
<lang groovy>assert closures instanceof List
assert closures.size() == 10
closures.each { assert it instanceof Closure }
println closures[7]()</lang>
Output:
<pre>49</pre>
=={{header|Icon}} and {{header|Unicon}}==
|