How can we convert between a program using `call/cc` and a program using functions written in CPS?

207 Views Asked by At

The Scheme Programming Language says

It turns out that any program that uses call/cc can be rewritten in CPS without call/cc, but a total rewrite of the program (sometimes including even system-defined primitives) might be necessary.

What are the general techniques to

  • convert a program using call/cc to a program using functions written in CPS

  • convert in the reverse direction?

1

There are 1 best solutions below

0
river On

You can learn how to implement the continuation passing transform here http://matt.might.net/articles/cps-conversion/ or from the book Compiling With Continuations by Appel.

The reverse transform is more difficult and has less practical applications but there is a paper about it: Back to Direct Style (1994) by Olivier Danvy