PEP 284, Integer for-loops
phil hunt
philh at comuno.freeserve.co.uk
Fri Mar 8 05:43:45 EST 2002
On Thu, 07 Mar 2002 09:36:10 -0800, David Eppstein <eppstein at ics.uci.edu> wrote:
>In article <slrna8dd1d.d3t.philh at comuno.freeserve.co.uk>,
> philh at comuno.freeserve.co.uk (phil hunt) wrote:
>
>> How about:
>>
>> for i = 1 to 10:
>>
>> or
>>
>> for i is 1 to 10:
>>
>> I think these are both equally good and both much preferable over
>> the horrible
>>
>> for 1 <= i <= 10:
>>
>> which I can only assume is someone's sick idea of a joke.
>
>Your "1 to 10" syntax (and most other ideas floated previously on this
>group) assumes a fixed type of interval (closed, I'm guessing, but it's
>not clear), and not even the most common type (half-open).
Not sure what you mean here.
> The proposed
>syntax makes explicit what would happen at the ends of the intervals.
>
>One alternative proposal, that didn't seem to have as much support but
>might still be worth looking at, was to allow the creation of ranges by
>"1 <= ... <= 10" (possible without much modification of the compiler via
>a clever enough definition of "...") so then one could do
>"for i in 1 <= ... <= 10".
>
>I would appreciate it if you could give me a more constructive criticism
>of PEP 284 than "horrible", "someone's sick idea of a joke", which don't
>give me much idea why you don't like it.
Thev reasdon i don't like it is that the syntax already has a
meaning: to compare the magnitude of values. Now you are proposing
another, totally different, meaning.
In a way what you are saying is (a <= b <= c) means return a list of
all the integer values of (b) that satisfy this statement.
But that isn't really true, because you can't do things like:
a <= b*2 <= c
or:
2 <= b and b*b <= c
etc.
So the system isn't fully general. In fact, its expressiveness is
*less* than the existing range/xrange system, in which you can
specify a step.
The onlyt problem with range/xrange, as I see it is that it always
excludes the to-value, ie.
range(0,3)
returns [0, 1, 2]
So perhaps it would be better if there were rangei/xrangei
functions, such that:
rangei(0,3)
returns [0, 1, 2, 3]
(Or has this been fixed in 2.2?)
--
<"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><">
"I would guess that he really believes whatever is politically
advantageous for him to believe."
-- Alison Brooks, referring to Michael
Portillo, on soc.history.what-if
More information about the Python-list
mailing list