[plt-scheme] Confusing continuation behavior (a question about)

From: Grant Rettke (grettke at acm.org)
Date: Thu Jul 17 22:57:30 EDT 2008

On Thu, Jul 17, 2008 at 6:36 PM, Anton van Straaten
<anton at appsolutions.com> wrote:
>> 1 -> 2 -> 3 -> 1 -> 2 -> 3 -> ...
>> 1. (a-process)
>> 2. (set! cond1 #t)
>> 3. (a-process)
>> 4. (set! cond2 #t)
> Here's a clue: after line 3 invokes the continuation that re-enters 'impl',
> what is the value of 'return'?

Here are my thoughts. I am still studying continuations. Honestly, I
have a hard time visualizing them, but from stepping through with the
debugger I think I've got a visual of what is happening along with my
rudimentary practice of converting simple functions to CPS style. Are
these thoughts correct?

The first time 'a-process' gets called at line 1, the the value bound
to 'return' is a continuation that looks like this:

(lambda (ignored)
    (set! cond1 #t)
    rest of program...))

The second time 'a-process' gets called at line 3, the value of
'return' is still the same as above because when impl was rebound,
that was the value bound to return. After the call at line 3, we
really want return to be bound to this:

(lambda (ignored)
    ;;;;; (a-process)
    ;;;;; (set! cond1 #t)
    rest of program...))

So the question is, when we pass control to impl that second time
after binding cond1 to #t, how do we access the *that* continuation
and bind it to return. I'm going to do some reading.

Posted on the users mailing list.