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

From: Anton van Straaten (anton at appsolutions.com)
Date: Thu Jul 17 19:36:13 EDT 2008

Grant Rettke wrote:
> I just cut it over to 4.0.2 with #lang scheme, and I get a behavior I
> don't understand, it basically enters an infinite loop because the
> execution of the program never reaches the point where cond2 gets set
> to #t. Instead, it just loops forever like this (I debugged it):
> 
> 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'?

Once you've figured that out, the obvious question is what should the 
value of 'return' be, and how can you set it to the right value?

Setting it to the right value might seem tricky depending on how 
comfortable you are with continuations.  More clues are available if 
necessary...

(A couple of other comments:

1. Matthew correctly identified why this used to work - there's a kind 
of bug in this code which was being hidden by the presence of prompts 
around top-level expressions in non-module-languages.  In Pretty Big or 
even in older PLT versions, if you wrap all the top level expressions in 
a function, it should reproduce the bug.

2. Jos Koot's solution doesn't achieve the desired effect, since it 
simply re-executes the whole of 'impl' every time.  impl is local with 
respect to 'process', so the effect of the set! is lost once control 
transfers out of the procedure.  This can be seen in the output which 
repeats "Condition 1 is met, going to condition 2" three times.)

Anton


Posted on the users mailing list.