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/ccto a program using functions written in CPSconvert in the reverse direction?
(call/cc (lambda (k) ...))==>(call/cc& (lambda (k) ...) k)==((lambda (k) ...) k). i.e.(define (call/cc& lam k) (lam k))is the definition. that's the simple story; I think there were some recent posts about the call/cc implementation in CPS, in scheme, try searching for them. - Will Ness(call/cc (lambda (k) ...))==>(call/cc& (lambda (k c) ...) c)==((lambda (k c) ...) c c). i.e.(define (call/cc& lam c) (lam c c))(under the scheme where the continuation is always passed as the last argument (which is of course an arbitrary choice)). - Will Ness