Closures/Value capture: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 2,197: | Line 2,197: | ||
Whenever we call a continuation, the <code>(block sqr ...)</code> environment is restored. and the suspended computation inside the block resumes by returning out of the <code>(suspend ...)</code> form normally. The block then executes to completion, returning the <code>(* cap cap)</code> form's value. At that point, our call to the continuation terminates, yielding that value. |
Whenever we call a continuation, the <code>(block sqr ...)</code> environment is restored. and the suspended computation inside the block resumes by returning out of the <code>(suspend ...)</code> form normally. The block then executes to completion, returning the <code>(* cap cap)</code> form's value. At that point, our call to the continuation terminates, yielding that value. |
||
=={{header|Wren}}== |
|||
<lang ecmascript>var fs = List.filled(10, null) |
|||
for (i in 0...fs.count) { |
|||
fs[i] = Fn.new { i * i } |
|||
} |
|||
for (i in 0...fs.count-1) System.print("Function #%(i): %(fs[i].call())")</lang> |
|||
{{out}} |
|||
<pre> |
|||
Function #0: 0 |
|||
Function #1: 1 |
|||
Function #2: 4 |
|||
Function #3: 9 |
|||
Function #4: 16 |
|||
Function #5: 25 |
|||
Function #6: 36 |
|||
Function #7: 49 |
|||
Function #8: 64 |
|||
</pre> |
|||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |