[Top][All Lists]

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

Re: [Chicken-users] Continuations

From: John Cowan
Subject: Re: [Chicken-users] Continuations
Date: Sat, 16 Jul 2016 21:40:42 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

Josh Barrett scripsit:

> A continuation is a capture of your location in a program, and its pending
> operations to return a result. In other languages, this is often
> represented by the stack.
> When a continuation is captured, the current state of the stack is captured
> and can be restored later.

So far so good.

> The value of variables within the scope of the continuation are not
> captured: if variables are initialized within a lexical context, a
> continuation of that context is captured, the values of those variables are
> altered, and the continuation is restored, the variables will not reset to
> their original values.

No, this is not true.  The local variables are also on the stack and
are captured along with the return addresses.  Variables that are above
the point where the continuation was captured cannot be restored if they
have been changed.

> In chicken, capturing a continuation is cheap, because you need only take a
> pointer to a set of data, and register that with the GC. In most other
> scheme implementations, escpecially those with a stronger focus on C
> interop, capturing a continuation is expensive, because you need to copy
> the entire program stack.

There are ways to make it cheaper, but basically yes.  In Chicken, you pay
for cheap continuations by occasionally paying much more for ordinary
procedure calls (those that fill the C stack and trigger minor garbage
collections).  In other systems, programs that don't capture continuations
don't pay for them.

John Cowan        address@hidden
Is not a patron, my Lord [Chesterfield], one who looks with unconcern
on a man struggling for life in the water, and when he has reached ground
encumbers him with help?        --Samuel Johnson

reply via email to

[Prev in Thread] Current Thread [Next in Thread]