guile-devel
[Top][All Lists]
Advanced

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

Re: continuation efficiency


From: Thomas Bushnell, BSG
Subject: Re: continuation efficiency
Date: 06 Jul 2001 18:01:26 -0700
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Marius Vollmer <address@hidden> writes:

> Contrary to what I said in an earlier post, I now think that cleanup
> actions _are_ important in reaction non-local exits.  Using
> dynamic-wind can not provide these cleanup actions since the `leave'
> thunk can not know whether the control flow will return eventually.
> Thus, dynamic-wind is only useful for changes to the system that have
> a dynamic extent.  Examples are setting global parameters like the
> current ports or the current module (eek!).

I agree that they are important, but you have missed the right way to
use dynamic-wind I think.

If you want to prevent a call into a dynamic-wind, you need to provide
an "enter" thunk that errors out on any call but the first.  

But the ideal way to deal is for the "enter" thunk to set up whatever
state is destroyed by the "leave" thunk.  That's how you are supposed
to use dynamic-wind, and it's a perfectly good way to provide cleanup
actions.

call/ec might be a useful performance enhancement (if the interpreter
knows about it specially, and it's not just a wrapper around call/cc),
but it doesn't provide any particularly useful extra semantic that
call/cc and dynamic-wind don't already provide perfectly well.

It's easy to write an exception handling system that provides traps,
faults, and errors in Scheme.  (Errors are non-returnable exceptions;
traps and faults can return, with a fault re-trying the faulting
operation and a trap skipping past it.)  

The puzzle you might be thinking of is with traps and faults: if the
handler is found as a continuation stored away somewhere, then maybe
you'll run some dynamic-wind exit handlers on the way to the
continuation, which then returns back in!  No problem: it's the job of
the dynamic-wind entry handler to put things back into the right
state.  Failure to do that would be a programming error.

However, the natural implementation of traps and faults is not with a
continuation, but with just a normal procedure.  (Actually, a stack of
them; which stack is managed by dynamic-wind.)  

Thomas



reply via email to

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