[Python-ideas] [Python-Dev] Inclusive Range (original) (raw)

Masklinn masklinn at masklinn.net
Tue Oct 5 13:05:43 CEST 2010


On 2010-10-05, at 12:52 , Carl M. Johnson wrote:

In the particular case, the correct way to represent an integer between 2 and 12 wouldn't be a, b, c, or d. It would be i in range(2, 12) You don't seem to realize that a, b, c and d are behaviors of languages, and that range can map to any of these 4 behaviors. The current range implements behavior a, the proposed one implements behavior c. a, b, c and d are simply descriptions of these behaviors in mathematical terms so as not to rely on language-specific concepts.

(if we were creating a new language that was 1 indexed and range was likewise adjusted), the list [1] would be range(1), and the empty list would be range(0), so the whole issue could be neatly sidestepped. :-) I fail to see what gets sidestepped there. Ignored at best.

As for l == l[:x] + l[x:y] + l[y:] where y > x, I think a case can be made that it would be less confusing as l == l[:x] + l[x+1:y] + l[y+1:], since you don't want to start again with x or y. Why not?

You just ended at x. When you pick up again, you want to start at x+1 and y+1 so that you don't get the x-th and y-th elements again. ;-) Yes indeed, as you demonstrate here closed ranges greatly complexify the code one has to write compared to half-closed ranges.



More information about the Python-ideas mailing list