On Fri, 8 Oct 2004, Leopold Toetsch wrote:

> Guido is to blame. Python generators/coroutines work like this:
>
>    iter = coro()     # first time calling
>    for x = iter() ...# iterate
>
> And that's what Parrot is doing too with the --python switch. But there
> is more ugliness: Python returns "None" if the generator is left through
> the end and a StopIteration is thrown (which you have to catch).
>
> That's all really messy and needs definitely some cleanup. OTOH it was
> the most straight forward translation of Python bytecode.


I get it now. Thanks.

When you have the AST handy, it's easier and cleaner
to just produce a different set of opcodes when you
know you're in a generator. Instead of returning None
at the end, pirate just directly raises a StopIteration
exception. That seems to me like it's a lot cleaner.

Is there any way we could get a temporary --pirate flag that
did everything --python did EXCEPT for the generator stuff?


- Michal
http://withoutane.com/

Reply via email to