Thoughts on PEP284

Stephen Horne $$$$$$$$$$$$$$$$$ at $$$$$$$$$$$$$$$$$$$$.co.uk
Tue Sep 23 05:59:32 CEST 2003


On Mon, 22 Sep 2003 22:41:04 -0400, "Sean Ross"
<sross at connectmail.carleton.ca> wrote:

>"Stephen Horne" <$$$$$$$$$$$$$$$$$@$$$$$$$$$$$$$$$$$$$$.co.uk> wrote in
>message news:5j4vmvgnr5v68f6lupbpgt0mop6l7ps2sn at 4ax.com...
>>
>> Some more looping thoughts - this time on integer for loops...
>
>Hi.
>How about the following:
>
>for i in 0...10:
>    # suite
>
>where 0...10 works something like xrange(10). So you get i=0 then 1 then 2
>... then 9. To get 0 thru 10, inclusive, you'd need to say 0...11 (Ruby has
>0..10, but I doubt that'd pass muster here).

Personally, I think the conventional '..' has more chance than your
'...'. Basically, the idea of '..' specifying an inclusive range is a
familiar idea to most people, even those who haven't used languages
like Ruby or Ada that use that notation. Having a syntax that looks
similar but means something just slightly different is likely to be
seriously error prone and confusing.

I'm certainly not against '..' in the conventional sense (I like
half-open ranges, but I'm not a fundamentalist and inclusive ranges
have worked perfectly well in Basic and Ada (and IIRC Pascal, Modula 2
and others).

Actually, the main reason I didn't mention it myself is that I figure
there must be some reason for its being rejected in the past. I can't
seriously believe that it has never been proposed.


>Leaving the ellipsis aside, you could add methods to int/long (also ala
>Ruby),
>
>for i in 0.upto(10):
>    # suite
>
># to count down
>for i in 10.downto(0):
>    # suite

I'm not sure about this - I'm bouncing between "that's neat!" and
"yuck!", but the "yuck!" part may just mean I need to get used to it.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk




More information about the Python-list mailing list