This has bothered me as well on several occasions, because it makes it impossible to do anything interesting with the additional information (e. g. giving an extended meaning to it, such as discussed here with indexing). For what it’s worth, Python ranges keep this information:
>>> range(1, -10)
range(1, -10)
>>> list(range(1, -10))
[]
1 Like
I vaguely recall someone a couple of years ago messing with changing a:b
to not normalize to a:max(a-1,b)
. Ultimately they abandoned it. I recall that length
needed to be redefined from b-a+1
, presumably to something like max(b-a+1,0)
, but surely there must have been something more sinister than that to have sunk it.
2 Likes
Do you remember what their motivation for trying was?
Nope. They wanted to be able to use the end value for something more interesting when the range was empty, but my memory is much too poor to remember more. I did a quick search through old PRs but didn’t find it. A more thorough search through issues and PRs might turn something up unless it was just a Discourse thread.