Closures/Value capture: Difference between revisions

Content added Content deleted
(→‎Desugared: Adding continuation-based solution.)
m (→‎Delimited Continuations: Close code tag.)
Line 1,420: Line 1,420:
The <code>suspend<code> operator suspends the execution of the <code>sqr</code> block, causing it to return the function <code>(op f nil)</code>. The variable <code>f</code> represents the captured continuation as a function. Continuation functions take one mandatory argument. We don't need that here, hence the <code>(op f nil)</code> expression is returned: it curries the one arg continuation function <code>f</code> to a function with no arguments.
The <code>suspend<code> operator suspends the execution of the <code>sqr</code> block, causing it to return the function <code>(op f nil)</code>. The variable <code>f</code> represents the captured continuation as a function. Continuation functions take one mandatory argument. We don't need that here, hence the <code>(op f nil)</code> expression is returned: it curries the one arg continuation function <code>f</code> to a function with no arguments.


The loop pushes these suspended continuations into a list, and then <code>nreverse<code>-s it.
The loop pushes these suspended continuations into a list, and then <code>nreverse</code>-s it.


We then interactively call the continuations in the list.
We then interactively call the continuations in the list.