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

Re: Demystifying Continuations




From: "David Simmons" <David.Simmons@smallscript.net>
> 
> Next semantics question:
> 
> Can I call an arbitrary continuation (not in my call-chain set)? 

Yes.

> In other words, if the continuation I call is not part of my current
> call-activation-chain, what happens to the current chain.
> 
> One of the following...
> a) The current chain is effectively unwound to its root and then
> replaced by the new continuation.
> 
> b) provided continuation is copied and grafted on to the tail of the
> current chain and then we continue.
> 
> c) The current chain is suspended/abandoned and we just jump to the new
> continuation. ** This mode has very significant semantic problems with
> respect to guard handlers/finally operations **

The answer is C, but let me address the guard handlers/finally operations.

First (and unfortunately?), `finally' makes no sense when you can
re-enter a continuation.  You have two options:  never have a finally
clause, or mark the continuation as non-reentrant and raise an
error on attempting to re-enter.

Guard handlers are a bit easier.  You have an `inside' and an `outside'
context.  When entering the continuation, you invoke the inside,
when leaving (for any reason) you invoke the outside.  When re-entering
you re-invoke the `inside'.  This is what dynamic-wind gives you.

Note that there are (at least) two flavors of this dynamic state.
The state you unwind/rewind on thread switch, and the state you
unwind/rewind `globally'.  The former might be a thread-local
value, the latter might be an open file.


> I'm assuming the answer is "c", and that a disjoint continuation
> represents a different thread. Which in turn means there are no unwind
> operations to perform since we are actually performing a thread-switch
> (where a call-activation-chain represents a thread).
> 
> -- Dave S. [www.smallscript.org]
> 
> > 
> > Michael
> >
>