Python / scheme implement

Daniel Yoo dyoo at hkn.eecs.berkeley.edu
Sun Aug 29 08:09:50 CEST 2004


510046470588-0001 at t-online.de wrote:
: Daniel Yoo <dyoo at hkn.eecs.berkeley.edu> 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:

    http://hkn.eecs.berkeley.edu/~dyoo/python/pyscheme/pyscheme-1.5pre.tar.gz

For example:

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

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


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

    http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/

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

    http://www.cs.indiana.edu/eip/eopl.html


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
announcement.


Hope this helps!



More information about the Python-list mailing list