Stefan Behnel wrote: > Hi, > > Dag Sverre Seljebotn wrote: >> 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. >>> >> 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. > > I vote for a) diverging behaviour between for-range and for-from for the > loop-variable after loop termination, and b) the obvious evaluate-once > semantics for the range() optimisation and the obvious (?) > evaluate-on-each-step semantics for the for-from loop.
Lucky for you, that's what sits in the tree right now, thanks to Magnus :-) Your thoughts on for-from seems like a good compromise, too. +1 Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
