Delimited continuations with shift and reset

Posted on October 23, 2015

I am working on the typed language implementation for Vicare; this code has its own branch. To take a small break, I added to the boot image the code for the syntaxes shift and reset which implement delimited continuations; the code is in the current head of the master branch.

I am truly ignorant on delimited continuations, I just took the code from http://mumble.net/~campbell/scheme/shift-reset.scm which implements the syntaxes on top of call/cc and adapted it for embedding in Vicare. This file claims:

This code is written by Taylor Campbell and placed in the Public Domain. All warranties are disclaimed.

I do not know the story of this implementation; I can see that it is similar to the one in the paper:

Martin Gasbichler, Michael Sperber: Final Shift for Call/cc: Direct Implementation of Shift and Reset, In The 2002 ACM SIGPLAN Conference on Functional Programming (ICFP ’02), Pittsburgh, Pa., October 2002, pages 271-282.

which is available on the Net. I have verified that the usual usage examples work:

(+ 1 (reset 2))
⇒ 3

(reset (* 2 (shift K (K 3))))
⇒ 6

(+ 1 (reset (* 2 (shift K (K 3)))))
⇒ 7

(reset (* 2 (shift K (K (K 2)))))
⇒ 8

(reset (* 2 (shift K (K (K (K 2))))))
⇒ 16

In some future I should take the time to actually study the implementation and truly test it (I am especially concerned with the use of a internal parameter).