Robert Kern, 02.12.2010 17:00:
> On 12/2/10 3:08 AM, Dag Sverre Seljebotn wrote:
>
>> Just in case anybody is wondering what something like this could look
>> like, here's a rough scetch complete with bugs. The idea would be to a)
>> add some rudimentary support for using the yield keyword in Cython to
>> make a generator function, b) inline the generator function if the
>> generator is used directly in a for-loop.
I know that we discussed these things ages ago, but I can't find the link ATM.
>> This should result in very
>> efficient code, and would also be much easier to implement than a
>> general purpose generator.
>
> I expect that being able to inline a generator would be quite a trick. I would
> go so far as to say that it is a completely different feature from adding
> generators to Cython in general. It's tantamount to adding (hygienic?) macros
> to
> Cython.
>
> I like it.
Note that we already have inlined generator expressions, i.e. things like
sum(2*x for x in seq)
get unfolded into a straight sum loop. Same for any, all and I forget what
others. And they already use the yield keyword for that purpose, so much of
what is needed is already there.
However, the transformation from general 1-yield generator functions won't
be trivial as the loop that runs over the generator function basically
needs to get moved inside of the generator code (the other way round would
be easier). This may involve some pretty hairy messing around with the
scoping rules. It's worth a try, though.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev