PEP 255: Simple Generators
tim.one at home.com
Sat Jun 16 01:29:49 CEST 2001
> 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
> 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,
> 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