>> The 'for i from...' version was a compromise
>>
>
> I understand that. Still, having two spellings for "for ... in ...", one
> for Python, one for C, looks better than a completely different syntax
> that just starts with "for". So I vote for
>
> for x in iterable:
>
> and
>
> for x in 1 < x <= 5:
>
Is this (int looping) something you tend to do? When writing Python code
I almost never end up doing it, rather I end up using "enumerate" (or
for NumPy, "ndenumerate") when I need the indices. I'd rather we worked
on improved high-level looping than inventing new syntax for low-level
looping.
For instance, one could implement optimizations for "enumerate" in
Cython as well as "range":
for idx, value in enumerate(a):
BLOCK
could be turned into the much more efficient
for idx from 0 <= len(a):
value = a[idx]
BLOCK
I suppose operating with C pointers increases the need for int looping,
but when working with C code I see a much larger need for
for (char* ch = start; *ch != 0; ++ch) ...
which could be done simply by letting our builting "enumerate" know that
char* should stop looping when hitting 0, also the more general
(especially in C++).
The more general iteration pattern (especially for C++):
for (T* iter = start; iter != v.end(); ++iter) ...
could be done by something like
for iterator in c_iteration(a.begin(), a.end()):
print iterator.get()
iterator.set(3)
and so on.
There are better alternatives to int iteration :-)
If that's not good enough, one should start with writing a
Cython-centric summary of the PEPs suggesting alternative looping
constructs for Python (of which there are no shortage), e.g.
http://www.python.org/dev/peps/pep-0284/
and
http://www.python.org/dev/peps/pep-0212/
My personal favorite would be "for x in [:10]:" so that one is
consistent with the slice notation (of course, this has the same
drawbacks as range does).
But really I'm -1 for anything that deals with a specific syntax
run-time syntax, I think all Cython-specific syntax should somehow be
connected with the fact that we have a compilation phase.
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev