PEP 284, Integer for-loops
John Machin
sjmachin at lexicon.net
Wed Mar 6 22:07:57 EST 2002
"Bjorn Pettersen" <BPettersen at NAREX.com> wrote in message news:<mailman.1015439892.7298.python-list at python.org>...
> > From: David Eppstein [mailto:eppstein at ics.uci.edu]
> > Subject: PEP 284, Integer for-loops
>
> Thanks for writing the PEP.
>
> I see this as a general proposal for a range syntax, and I disagree with
> it because:
>
> - it doesn't handle the general range issues, i.e. step value,
> and if we had to add yet another syntax to get general ranges
> it would be too confusing.
Agreed. Let's generalize the existing syntax.
Existing: for <var> in <sequence>:
Proposal: For a splendid blast from the past, let's take a leaf out of
ALGOL 60's book.
for <var> in <for-list>:
where the elements of <for list> can be of 3 different kinds:
(1) <arithmetic expression>
(2) <step-until-element> ::= <start-value> [step <step-value>] until
<last-value>
(3) <while-element> ::= <arithmetic expression> while <boolean
expression>
Lets you do things like
for k in 0,1,2, 5 step 5 until 25, k * 2 while k <=1024:
>
> - I would like range objects to be first class, ie. I would want
> to be able to pass ranges to functions, return them from
> functions, and do all the other things one can do with first
> class objects.
I don't understand this. range and xrange *are* first-class objects.
You can do all of those things.
>
> - It doesn't make the general case trivial, i.e.
> for 0 <= i < len(mySequence) is not much better than
> for i in range(len(mySequence) and is more verbose than
> for i in len(mySequence).
>
for i in 0, i+1 while i < len(mySequence):
for i in 0 until len(mySequence) - 1:
Hmmm, ... maybe not.
More information about the Python-list
mailing list