Closures/Value capture: Difference between revisions

Content added Content deleted
Line 393: Line 393:
{{out}}
{{out}}
<pre>[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]</pre>
<pre>[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]</pre>

=={{header|Delphi}}==
{{works with|Delphi 2009}}
<lang Delphi>program Project1;

type
TFuncIntResult = reference to function : integer;

var
Funcs : array [0..9] of TFuncIntResult;
i : integer;

begin
// Create 10 anonymous functions
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := function() : integer begin Result := i*i; end;

// call all 10 functions
for i := Low(Funcs) to High(Funcs) do
writeln( Funcs[i]() );

end.</lang>
{{out}}
<pre>0
1
4
9
16
25
36
49
64
81
</pre>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==