[Python-Dev] Lukewarm about range literals (original) (raw)
Greg Ewing greg@cosc.canterbury.ac.nz
Thu, 31 Aug 2000 14:33:36 +1200 (NZST)
- Previous message: [Python-Dev] Lukewarm about range literals
- Next message: [Python-Dev] Lukewarm about range literals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Tim Peters <tim_one@email.msn.com>:
I can't imagine why
for in 0 .. len(a)-1: isn't equally hated! Requiring "-1" in the most common case is simply bad design.
I agree with that. I didn't mean to suggest that I thought it was a good idea.
The real problem is in defining a..b to include b, which gives you a construct that is intuitive but not very useful in the context of the rest of the language.
On the other hand, if a..b doesn't include b, it's more useful, but less intuitive.
(By "intuitive" here, I mean "does what you would expect based on your experience with similar notations in other programming languages or in mathematics".)
I rather like the a:b idea, because it ties in with the half-open property of slices. Unfortunately, it gives the impression that you should be able to say
a = [1,2,3,4,5,6] b = 2:5 c = a[b]
and get c == [3,4,5].
for i = 1 to 10: # 1 to 10 inclusive
Endpoint problem again. You would be forever saying
for i = 0 to len(a)-1:
I do like the idea of keywords, however. All we need to do is find a way of spelling
for i = 0 uptobutnotincluding len(a):
without running out of breath.
Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+
- Previous message: [Python-Dev] Lukewarm about range literals
- Next message: [Python-Dev] Lukewarm about range literals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]