Closures/Value capture: Difference between revisions
Content added Content deleted
m (→Function image copying approach: just a typo) |
(→{{header|Groovy}}: new solution) |
||
Line 278: | Line 278: | ||
func #3: 9 |
func #3: 9 |
||
</pre> |
</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}}== |
=={{header|Icon}} and {{header|Unicon}}== |