Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A 'continuation' is the entire future of a computation. Every point in a computation has a continuation which, in naive terms, you can think of as the current program-counter and current stack. The Scheme <code>call/cc</code> function conveniently captures the current configuration and packages it up into a function. When you invoke that function you revert back to that point in the computation. Thus, a continuation is very different from a function (but the continuation function is, well, a function).</p> <p>There are two common cases where one typically sees <code>call/cc</code> applied:</p> <ol> <li><p>non-local exit. You establish a continuation, do some computation, to abruptly end the computation you invoke the continuation. </p></li> <li><p>restart/reenter a computation. In this case you save the continuation and then call it again as you please.</p></li> </ol> <p>Here is an example for case #1:</p> <pre><code>(begin ;; do stuff (call/cc (lambda (k) ;; do more ;; oops, must 'abort' (k 'ignore))) ;; continue on ) </code></pre> <p>And here is an example for case #2:</p> <pre><code>&gt; (define c #f) &gt; (let ((x 10)) (display (list (+ 1 (call/cc (lambda (k) (set! c k) x))) 111)) (display " more")) (11 111) more &gt; (c 20) (21 111) more &gt; (c 90) (91 111) more </code></pre> <p>For this case #2 is it worth noting that the continuation brings you back to the top-level read-eval-print loop - which gives you a chance to re-invoke the continuation in this example!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload