ANN: Pyrex 0.4.3
baas at ira.uka.de
Tue Aug 27 16:35:28 CEST 2002
On Tue, 27 Aug 2002 13:40:38 +1200, Greg Ewing
<see_reply_address at something.invalid> wrote:
> * A new kind of for-loop has been added to the language
> for iterating over ranges of integers. Example:
> for i from 0 <= i < 10:
> print i
> The main advantage of using this form is that it
> is translated into pure C code where possible, whereas
> an equivalent Python for-loop using range() is not.
What's the reason of introducing a new language construct instead of
transforming the old one into a pure C loop wherever possible?
As soon as the loop variable is a C numeric type and the sequence is
created with a call to range() or xrange() then pyrex could transform
the loop into a pure C loop (without actually calling range() or
I think this has several advantages:
- You don't have to learn a new language construct which is specific
to Pyrex, instead you can stick to the familiar construct and still
get a performance increase.
- Porting existing Python code to Pyrex for speed-ups is easier (You
only have to declare the loop variable as a C variable, and even this
could be optimized by Pyrex some day)
- You can use an arbitrary step size
So in my opinion the new for-loop just adds a bit of complexity to the
language without really giving something new. Therefore I'd rather
suggest to introduce an optimization step which transforms the Python
for-loop into a C for-loop whenever possible.
But probably I've missed something, so I'd be glad to hear other
opinions as well...
- Matthias -
More information about the Python-list