The code for the paper: Dynamic binding + Delimited control Copyright (c) 2006, Amr Sabry, Chung-chieh Shan, Oleg Kiselyov The code is released under the MIT license. Overview of the files Illustrating the ill-defined interaction between dynamic variables and shift/reset (implemented in the common way, call/cc+set!) Scheme code dynvar-via-exc.scm R5RS implementation of dynamic variables in terms of exceptions and call/cc. Illustration of the ill-defined interaction. This code directly corresponds to dynvar.sml below. dynvar-shift-srfi.scm Another R5RS code, similar to the above. It uses the reference SRFI-39 implementation of dynamic variables. The code traces the invocations of dynamic-wind actions and has the additional test for dynamic variables and shift-based `threads'. dynvar-scheme48-problem.scm using dynamic variables (aka fluids) and delimited continuations that are both provided in the same Scheme implementation: Scheme48. This is Scheme48-specific code. dynvar-shift-petite.scm The same example as in dynvar-shift-srfi.scm, only using (Petite) Chez Scheme's native implementation of parameter objects. This is Chez-specific code. trampoline-petite.scm Two, equivalent implementations of shift and reset (with and without trampolining) have observably different behavior in the presence of dynamic variables. This code uses (Petite) Chez Scheme's native implementation of parameter objects. shift-reset.scm Danvy/Filinski implementation of shift/reset, the Christmas present to Scheme48 authors. It is used by most of the above Scheme code. SML code dynvar.sml Implementation of dynamic variables in terms of exceptions and call/cc. Illustration of the ill-defined interaction with shift/reset. control.sml shift and reset: See Filinski's thesis escape.sml better type for call/cc: See Filinski's thesis sources.cm Compilation Manager project to run the code. At the SML/NJ prompt, enter: CM.make "sources.cm"; Other (more realistic) examples of how easy it is to encounter the undesirable behavior of the common implementations of delimited continuations and dynamically-scoped variables. The two features, as commonly implemented, interact in ill-defined ways. chez-extended-ex.scm (Petite) Chez-specific code, which uses Chez's native parameter objects to control the printing of objects. The parameterization may fail for some print expressions clearly within parameterization's dynamic scope. exceptions-shift.scm Scheme48-specific code, which uses Scheme48-provided delimited continuations and exception handling forms (which, in turn, rely on dynamic variables). The undesirable behavior is the failure to catch an i/o exception and do the clean-up action. In Haskell, dynamic binding is supported by the environment monad, Reader. We illustrate various interactions of the monad transformer ReaderT with the (delimited) continuation monad transformer. We observe that certain frequently occurring code patterns cannot be expressed at all with the monad transformer mechanism because no (static) combination of ReaderT and CC layers does the job. reader.hs ReaderT and ContT The new implementations of dynamic binding in terms of delimited continuations, which is consistent with the combined context-reduction semantics DB+DC (see the paper). The code also includes the examples from the above -- which now have the expected, in the semantics of DB+DC, behavior. Scheme new-parameters.scm The re-implementation of the parameter objects for Chez Scheme. The code is actually portable R5RS + records. Requires cc-ref.scm below. Implementation of the delimited continuation interface of Dybvig, Sabry, Peyton-Jones' cc-ref.scm The implementation itself: R5RS + records cc-ref-tests.scm The regression tests OCaml caml-dynvar.ml Dynamic variables in OCaml, via delimited continuations. The code requires caml-shift http://pobox.com/~oleg/ftp/continuations/implementations.html#caml-shift Haskell Dynvar.hs Dynamic variables in Haskell, via the CC monad transformer. The code requires an implementation of Dybvig, Sabry, Peyton-Jones' delimited continuation monadic framework The new implementation of delimited continuations (shift/reset), which is aware of dynamic-wind and dynamic-environment. The code also includes the examples from the above -- which now have the expected, in DB+DC, behavior. The implementation is necessarily platform-specific as R5RS does not provide the necessary tools. new-shift.scm Scheme48-specific code. That implementation of shift/reset now behaves as expected in DB+DC, with respect to Scheme48's native dynamic variables _and_ dynamic-wind. Last updated: June 2006.