Python / scheme implement

Daniel Yoo dyoo at
Sun Aug 29 08:09:50 CEST 2004

510046470588-0001 at wrote:
: Daniel Yoo <dyoo at> writes:
:> It's not perfect (and frankly, is a little outdated!), but it's a
:> proof-of-concept that one language can model the other.

: how does python model call-with-current-continuation?

Hi Klaus,

I'm not sure if you meant that question to be a challenge, but I'll
take it up!  *grin*

The question is slightly off: there's nothing about Python in
particular that prevents us from implementing call/cc.  It does,
however, take a bit of work: implementing call/cc involves a rewrite
of the interpreter into a CPS form.

It's actually not too bad, and I have now done this.  As a nice side
effect, we also get proper tail recursion!  Hurrah!

You can take a look at the updated code here:

For example:

volado:~/Documents/work/pyscheme/trunk/src dyoo$ python
Welcome to PyScheme!  Type: (QUIT) to quit.

[PyScheme] >>> (+ 1 (call/cc (lambda (k) (+ 2 (k 3)))))

The improvements are due to ideas I stole from Shriram Krishnamurthi's
"Programming Languages: Application and Interpretation":

and Friedman, Wand, and Haynes "Essentials of Programming Languages":

I'm psyched now: I think I finally understand continuations!  *grin*

I do have to fix a major bug with pair representation in pyscheme.
But as soon as I get that outstanding fixed, I'll send a more formal

Hope this helps!

More information about the Python-list mailing list