Closures/Value capture: Difference between revisions
Content added Content deleted
(Adding Lua Solution) |
|||
Line 585: | Line 585: | ||
yes |
yes |
||
</lang> |
</lang> |
||
=={{header|Lua}}== |
|||
<lang Lua> |
|||
funcs={} |
|||
for i=1,10 do |
|||
table.insert(funcs, function() print(i, i*i) end) |
|||
end |
|||
funcs[2]() |
|||
funcs[3]() |
|||
</lang> |
|||
Output: |
|||
<pre>2 4 |
|||
3 9 |
|||
</pre> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |