# -*- Mode: Python; tab-width: 4 -*-

"""

We'd like to experiment with coroutine-based async i/o... but python
doesn't give us call/cc.

Can we implement coroutines in a language that does not support
call/cc?  Theoretically, yes: If we can CPS-transform the program,
then we can do it.  But is this practical?  The only requirement is
first-class procedures?  [is it practical with python?  [python can
create several thousand lambda's per second] ]

I suppose a starting place would be a simple coroutine program: if
we can do this in python, then perhaps we can do an asyncore...

But would this have an impact on user programs?  Would they have to be
written in CPS?  [in a sense they already are...] Or could they be
written as if they were multi-threaded?

...

Is it possible to write a CPS-transformer for python? [using the AST
module?]  How does the lack of real environments affect this?

simple example:
--------------------
chains a & b, wheel w

1  <chain a> attempts a blocking operation.  [s.send (data, k)]
2  <k> (the continuation) is then stuffed away in <w> which will
   wait until something fires.
3  <b> fires... presumably <b> was blocked, and its continuation
   <v> was stored.  invoke it.
4  etc...   

This requires the calls to send, etc. to all be in CPS.  Can we
'hide' the CPS at some level?  If so, where?

Let's imagine it is possible to hide the CPS code.

Then the signature of <send> would look like this:

	def send (self, data):
		blah blah blah

And there would have to be some way of capturing the
continuation.

[the more I think about this, the more I think asyncore/etc...
have done it already, at least as far as it can go in python]




"""

