PEP 255: Simple Generators
Tim Peters
tim.one at home.com
Fri Jun 15 19:29:49 EDT 2001
[Nick Perkins]
> neat!
> simple, powerful, and easy to understand!
>
> This reminds me of 'contiuations', a la 'call/cc' in Scheme.
> ( a little harder to understand )
> I understand that call/cc can be used to implement all kinds of control
> structures. Yeild sounds more like "set entry point to current
> continuation, and return"
See the references to Stackless in the PEP; Stackless implements
continuations for Python.
> Could it be used to turn a partially-evaluated function into a
> first-class object?
Hmm. If you can paint with a hammer, or pound nails with a paintbrush, sure
<wink>.
> You could have a function that takes it's arguments, "yeilds"
> None, and then waits for it's next invocation to actually 'do the
> dirty work'. ...wait..can they take args?...
Can what take args? Generator-functions can certainly take args.
> What are the implications of generators resembling continuations,
None, because:
> and what is the liklihood that generators will be used/misused/abused
> to implement tricky control structures?
Also none: a generator can yield only to its immediate caller. In that
sense it's no more powerful (or difficult to implement) than call/return.
It can't "remember the state of the call stack", a generator can only
remember its own local state, and it can't yield to any places other than
the places from which it's explicitly called. That's what spares generators
from the implementation headaches of full-blown continuations.
think-of-'em-as-resumable-functions-ly y'rs - tim
More information about the Python-list
mailing list