[Cython] Fix for #196 (for loop bug)
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Fri Jan 30 14:30:57 CET 2009
Magnus Lie Hetland wrote:
> For the for-from loop, this may be intended -- as you say, it mimics
> the C behavior (although it seems to fly in the face of "Python
> intuition"): Even with the existing Cython semantics, getstep() will
> be called after *every iteration*.
>
> It seems to me that in
>
> for 0 <= i < n by getstep(): pass
>
> one would expect (in Python) that the step expression be evaluated
> only once. If that is not the case, fine. Then the for-from loop can
> safely be left alone as it is. (If not, a local variable should
>
I think so -- the for-from loop is a C idiom from which one can expect C
behaviour from my perspective, and if this has been the behaviour so far
then backward compatability alone speaks against altering it. The range
optimization has been around for much shorter and clearly should behave
as Python range, so that story is different.
(Well, my real perspective is that for-from should be deprecated and
removed prior to a 1.0 release, but let's not have that war now :-) )
Dag Sverre
More information about the Cython-dev
mailing list