Closures/Value capture: Difference between revisions

Content added Content deleted
(Added Io entry)
(Added Elixir)
Line 52:
{{out}}
<pre> 1 4 9 16 25 36 49 64 81</pre>
 
 
=={{header|ALGOL 68}}==
Line 78 ⟶ 77:
 
Using partial parametrization as proposed in Algol Bulletin by Charles Lindsey. Algol68G does not support binding ''all'' actual parameters "partially" without deproceduring, so a PROC(BOOL)INT mode is used instead of a PROC INT. The variable ''captured i'' is passed twice, once by reference and once by value, to demonstrate that it is possible to capture both ways, and a little extra code is added to show that the closure can modify the captured variable.
 
 
=={{header|AntLang}}==
Line 555 ⟶ 553:
{{out}}
<pre>9</pre>
 
=={{header|Elixir}}==
<lang elixir>funs = for i <- 0..9, do: (fn -> i*i end)
Enum.each(funs, &IO.puts &1.())</lang>
 
{{out}}
<pre>
0
1
4
9
16
25
36
49
64
81
</pre>
 
=={{header|Emacs Lisp}}==
Line 1,006 ⟶ 1,022:
 
</lang>
 
=={{header|Logtalk}}==
The example that follow uses Logtalk's native support for lambda expressions.