[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: So, what the heck is a continuation anyway?




  > X-Sender: dan@pop.sidhe.org
  > Date: Mon, 10 Dec 2001 15:39:41 -0500
  > From: Dan Sugalski <dan@sidhe.org>
  > Content-Type: text/plain; charset="us-ascii"; format=flowed
  > Sender: owner-ll1-discuss@ai.mit.edu
  > Precedence: bulk
  > 
  > At 03:11 PM 12/10/2001 -0500, Shriram Krishnamurthi wrote:
  > >Dan, here's an explanation that should make sense to an assembly hacker:
  > >
  > >One simple way to think of a continuation is
  > >
  > >   It's the stack.
  > >
  > 
  > Is the copying fully required, and does anything that happens after the 
  > snapshot's taken affect the snapshot?
  > 
  > For example, if I have:
  > 
  >     {
  >        int i = 0;
  >        make_continuation();
  >        print i;
  >        i = 3;
  >     }
  > 
  > Will that print 0 or 3 when the continuation is invoked? And if I invoke 
  > that continuation a second time will it print 0 or 3?


That's where Shriram's simple explanation breaks down. Suppose you had
taken an EOPL-based course on interpreters (junior level). Then Shriram 
would have told you 

 the continuation is the closure representation 
 of the rest of the computation with a built-in 
 "abort" 

That would have explained that the continuation closes over the environment
of the interpreter but not the state (memory). So Shriram should have said 

 "it's a copy of the control state."

The answer to your question: since i is state, it changes across
continuation invocations. 

An answer to a question that you didn't ask: 

 do NOT (did you see the caps?) capture continuations with a function such
 as make_continuation() -- been there, done that, bad idea. 

-- Matthias

P.S. BTW, you forgot the implicit invocation of your continuation. You
really had three of them.