Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No. Typically, undelimited continuations (eg created with Scheme's <code>call/cc</code>) jump when you invoke the <code>continuation</code>, not when you call <code>call/cc</code> (aka <code>call-with-current-continuation</code>).</p> <p>So, fleshing out your example:</p> <pre><code>continuation savedk; void foo(int arg) { ... } int bar() { ... call/cc(handler) // after call/cc println "after call/cc" ... } void handler(continuation k) { savedk = k } foo ( bar() ) // after foo invocation </code></pre> <ol> <li><p>Execution starts. We enter <code>bar</code> (we haven't entered <code>foo</code> yet; we'll do that when we get done with <code>bar</code>).</p></li> <li><p>When we hit the call to <code>call/cc</code> in <code>bar</code>, the "program context" is turned into an object called a continuation. At this point, the program context consists of "finish executing <code>bar</code>, then call <code>foo</code> on the result, and then do whatever comes after the <code>foo</code> invocation". The continuation is passed to the function given as an argument to <code>call/cc</code>, which is <code>handler</code> in my example above.</p></li> <li><p><code>handler</code> does something with the continuation. Let's assume it stores it in a global variable. Then it returns to the point right after the <code>call/cc</code> call, still inside of <code>bar</code>.</p></li> <li><p>Let's say we print something out at this point. Then <code>bar</code> finishes and we call <code>foo</code>, and it finishes.</p></li> <li><p>If we now apply the continuation in <code>savedk</code>, control jumps back into <code>bar</code> and restores the program context to "finish executing <code>bar</code>, then call <code>foo</code> on the result, and then do whatever comes after the <code>foo</code> invocation". So we get another line printed. In fact, if we don't clear the <code>savedk</code> variable or test some other state, we might get an infinite loop if "do whatever comes after the <code>foo</code> invocation" is call <code>savedk</code> again!</p></li> </ol>
    singulars
    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.
    3. 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