Range Operation pre-PEP

Delaney, Timothy tdelaney at avaya.com
Thu May 10 02:07:56 EDT 2001


Firstly, I don't personally feel there is a need for a new notation, but it
is fun to work out what would work best were we indeed to have one ...

> > Well, there would be a simple way to make ranges that 
> conformed to both.
> Use
> > the mathematical notation for describing inclusive and 
> exclusive bounds
> > (although it would be using '..' instead of ',').
> >
> > If I remember correctly ...
> >
> > [0..10] - range is 0 to 10
> > [0..10) - range is 0 to 9
> > (0..10] - range is 1 to 10
> > (0..10) - range is 1 to 9
> >
> Correct me if I'm wrong, but don't the concepts of open and 
> closed intervals
> belong to analysis and not discrete mathematics -- in other 
> words, they
> apply to infinite sets but not finite ones. An open interval 
> (x,y) is the
> set of all numbers strictly greater than x and strictly less than y.
> Dedekind will be turning in his grave...

Well, there are *no* infinite sets in computing, so it's not generally
applicable here (the largest long integer in Python for example must be
bound by the amount of memory available to the Python process).

That may well be true (been a few years since I've done any formal maths
work/study), however it is fine system (which is an infinite set) 9 is the
greatest integer strictly less than 10.

It's is perfectly valid to define the set you are using - this notation
would only be valid for the set of integers (including long integers
naturally).

> This proposed notation (and you aren't the first to propose 
> it) would be
> bizarrely misunderstood by newcomers. I certainly don't want 
> to have to
> explain that the same object can be described in four 
> different ways, and
> suggest when [1..9] is more appropriate than (0..10) is more 
> appropriate
> than [1..10) is more appropriate than (0..9].
> 
> So, why have four representations for the same thing?

Again, I personally agree ... you may have noticed my comment "There -
everyone is happy" ... ;) OTOH, I think inclusive lower-bound, optional
inclusive upper bound i.e. [] and [) would be useful. Having optional
exclusive lower bound was just a bit of fun.

Also, remember that it is quite possible to create a range counting down ...
in some cases I could see exclusive lower bound, inclusive upper bound being
useful (except that's really ex upper, in lower, but in reverse ...).

Tim Delaney




More information about the Python-list mailing list