lua-users home
lua-l archive

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


steve donovan <steve.j.donovan@gmail.com> writes:

> On Tue, Feb 22, 2011 at 3:09 PM, Gunnar Zötl <gz@tset.de> wrote:
>> Anyways, call/cc would be so brilliant :)
>
> I've tried to understand Scheme continuations, but so far this brain
> has refused to make the jump.

Well, you presumably know the normal call/return mechanism in connection
with a call stack.  Now you just don't use a separate call stack, but
just place it on the normal heap and let it be subject to
garbage-collection like anything else.  So far so good.

A return is then not final as long as you keep a reference to the
associated continuation object.  You can return again to the same place
in the logic of things.

In fact, the Chicken scheme compiler does just that: it never actually
returns, but if the return stack grows too large, it gets
garbage-collected.

Now Scheme is actually a rather pointless language for actually working
with continuations since most of its data _structures_ (like a list) are
static and not maintained inside of the call stack/heap.

That means that if you use a continuation, very little is actually
reliably being rewound to the state of the previous call/return.

call/cc may be brilliant, but it is basically only used as a low-level
tool for implementing more understandable constructs.

-- 
David Kastrup