Closures/Value capture: Difference between revisions

Content added Content deleted
m (→‎Delimited Continuations: Spurious parens removed.)
m (→‎{{header|Sidef}}: added a simpler example)
Line 1,244: Line 1,244:
=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>var f = (
<lang ruby>var f = (
0...9 -> map {|i| func(j){i * j} }
0 ..^ 9 -> map {|i| func(j){i * j} }
);
);


0 ..^ 8 -> each { |j|
0 ..^ 8 -> each { |j|
say f[j].call(j);
say f[j](j);
};</lang>
}</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,261: Line 1,261:
49
49
64
64
</pre>

Starting from i=1:
<lang ruby>var f = 10.of { |i|
func(j){i * j}
}

9.times { |j|
say f[j-1](j);
}</lang>
{{out}}
<pre>
1
4
9
16
25
36
49
64
81
</pre>
</pre>