Does it make any difference, if the start point in a range() is a function
call or even if it is modified to a new value inside the loop?  Even if it
is modified, the start would be evaluated only once, isn't it?  I defined a
start function and supplied it to the range() and from the output it looked
like start is called once, and also the c output seems to agree with this.
In this case if the start is a function call, then it doesn't have to be
handled right?  I am not sure if I have caught the topic right!  Or am i
missing something here?


On Wed, Mar 18, 2009 at 3:33 AM, Robert Bradshaw <
[email protected]> wrote:

> On Mar 17, 2009, at 2:35 PM, Greg Ewing wrote:
>
> > Dag Sverre Seljebotn wrote:
> >
> >> ForFromStatNode is used in two situations in Cython code; in the
> >> Cython-specific syntax
> >>
> >> cdef int i
> >> for i from start <= i < end [by step]:
> >>     ...
> >>
> >> In the former case, end should NOT be frozen (i.e. if it is a
> >> function
> >> call it should be called again for every iteration
> >
> > Has Cython changed this? It's not how the for-from
> > statement works in Pyrex -- the limits are only
> > evaluated once.
>
> No, Cython has not changed this, and I'm not sure we should. But
> there is some inconsistency:
>
> %cython
> cdef int get_bound(int m):
>     print "get_bound(%s)"%m
>     return m
>
> def test_var(int n, int m):
>     cdef int i
>     for i from 0 <= i < n:
>         print "at", i
>         n = m
>     return i
>
> def test_func(int n):
>     cdef int i
>     for i from 0 <= i < get_bound(n):
>         print "at", i
>     return i
>
> sage: test_var(10, 5)
> at 0
> at 1
> at 2
> at 3
> at 4
> 5
> sage: test_func(5)
> get_bound(5)
> at 0
> at 1
> at 2
> at 3
> at 4
> 5
>
> - Robert
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
Regards,
Anoop S.

People who says, "It's not winning or losing that matters, but
participation", probably lost.
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to