[plt-scheme] composable continuations and dynamic state

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Thu Jun 4 12:29:03 EDT 2009

Taylor R Campbell wrote:
> [By the way, thanks for cc'ing me -- I forgot to mention in my first
> message that I am not subscribed to the list.]
>    Date: Thu, 04 Jun 2009 02:04:43 -0400
>    From: Ryan Culpepper <ryanc at ccs.neu.edu>
>    The thread cell indirection is, as you surmised, totally irrelevant to 
>    the results. You're seeing the effects of another indirection, the 
>    "parameterization". Parameter-value associations are not stored 
>    individually in the continuation. Instead, the continuation contains 
>    "parameterizations", or mappings of all parameters to their current 
>    values (really, to their currently associated thread-cells). 
>    Consequently, when you separate a continuation into parts, you do *not* 
>    separate the parameter updates belonging to those parts.
> OK, thanks: now I understand the mechanism yielding the output shown.
> My next question is about the rationale:  Why are DYNAMIC-WIND state
> points only partially preserved, whereas parametrizations are fully
> preserved?

I suspect the behavior comes from the early days when parameters were 
first added, when it seemed like first-class parameterizations were a 
useful feature: capture a parameterization over here, ship it somewhere 
else and reinstate it there. I thought that they were no longer used, 
but a search for 'parameterization' in the source tree does turn up a 
number of hits.

It also seems like storing parameterizations might make parameter 
lookups faster, but I haven't tried to test that conjecture. Perhaps 
Matthew has?

> [...]
> In lieu of the way parametrizations are implemented, I think I
> understand the mechanism that yields this result (simply putting a
> parametrization in the continuation of CWCompC has the effect of
> saving all the parameters in the composable continuation), but I don't
> think that makes the high-level behaviour any less surprising.
> Now, the current semantics of composable continuations and dynamic
> state suggest to me that a naive user (such as me) might attempt to
> mix DYNAMIC-WIND and PARAMETRIZE with disastrous results.  I don't
> have a good example of this right now, but here's a pathological one
> to keep you occupied.  Consider a naive recursive mutex in terms of a
> semaphore and a parameter that tells us whether we already have the
> mutex locked:
> [...]

In fact, I got bitten by the parameter issue the last time I played with 
delimited continuations. If you're using delimited continuations, I'd 
recommend avoiding parameters and using continuation marks or a light 
abstraction thereof (like the "dynamics" I sent in my previous message). 
More precisely, avoid using 'parameterize' in code that may be appear in 
a composable continuation.


Posted on the users mailing list.