Non-Deterministic Evaluation In Under 300 Bytes

Christian Tismer tismer at
Sun Mar 26 14:59:03 CEST 2000

Michael Hudson wrote:
> I was playing around with Chris Tismer's stackless python today, and
> wondering what I could actually use continuations for, so I pulled my
> copy of On Lisp off the bookshelf and came up with:

[A really nice example that I could never imagine!]

Thank you, this is incredible.

> 2) call-with-current-continuation is a *really bad* interface to the
>    continuation world, at least from the point of actually
>    understanding the code (I implemented the above by writing a
>    call/cc function, transliterating the scheme version Graham
>    presents in the book, and then "unwinding" the calls to
>    call/cc. The result made more sense then the original - even than
>    the scheme!). Chris's approach is better, at least for me.

On the call/cc issue: I have been tinkering with this
at length. It is easy to write your own call/cc with
Stackless Python, but it turned out to be not so very useful,
for a couple of reasons:

- Having an explicit continuation as a parameter can cause
  unwanted circular references which are hard to remove.
- Python gives you an implicit continuation all the time:
  You always have a caller. Tis is the frame where the
  return statement would usually return to.
  This makes it easy to catch your caller just when it
  is needed.
- You still *can* use direct call/cc style if you need it.
  This is about 3 lines of Python code.

All in all, it turned out to be more natural to use just
the continuations which Python gives you for free. A major
problem was how to access them easily. The most powerful
and complication-less functions are:

continuation.caller()            - get me my caller
continuation.return_current()    - return *me* to my caller

The latter is new with Version 1.1, and it was exactly
the missing counterpart for caller. It allows you to
initialize a function via the normal call interface
and then jump back immediately, returning your own
continuation as a callable object.

see you soon at with SLP 1.1 - chris

Christian Tismer             :^)   <mailto:tismer at>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship*
14163 Berlin                 :     PGP key ->
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home

More information about the Python-list mailing list