[Python-Dev] functional continuations
Phillip J. Eby
pje at telecommunity.com
Sat Dec 15 17:57:51 CET 2007
At 01:04 AM 12/15/2007 -0800, tomer filiba wrote:
>* do you suppose it will work? are there any drawbacks i didn't
>anticipate?
Yes. :)
Specifically, think about what happens when a C function is in the
call stack, e.g.:
def f1():
return map(f2, [1,2,3])
def f2(ob):
raise WaitFor(something)
return ob
print f1()
If I understand you correctly, when this program is run, it will
print "1", rather than "[1, 2, 3]", because there is no way for you
to keep track of the internal state of the 'map()' call.
And this isn't just a problem for map() -- even something as simple
as a property access passes through C code whose state can get lost.
I don't think this approach is practical; you'd be better off using a
co-routine stack and trampoline, since the nature of generators
naturally forces all the C code out of the picture.
More information about the Python-Dev
mailing list