Status of PEP's?

Bjorn Pettersen BPettersen at NAREX.com
Fri Mar 1 08:42:59 EST 2002


> From: David Eppstein [mailto:eppstein at ics.uci.edu] 
> 
> In article <mailman.1014944882.14890.python-list at python.org>,
>  James_Althoff at i2.com wrote:
> 
> > For example, one problem I had when playing with an experimental 
> > implementation of the "middle argument" variant mentioned above is 
> > that the specific relational operators are tied to the 
> values of the 
> > bounds.  If you want to iterate from the smaller value (up) to the 
> > larger value you write:
> > 
> > for 1 <= var < 5:
> > 
> > whereas if you want to iterate from the larger value (down) to the 
> > smaller value you have to turn things around and write:
> > 
> > for 5 > var >= 1:
> > 
> > which all looks very nice when you are dealing with literal 
> constants.  
> > But suppose you have variables for the bounds, "start" and "end"?  
> > Let's say I have a function
> > 
> > def doSomethingFromTo(start,end):
> > 
> > The function has to test to see which of "start" and "end" is the 
> > smaller value in order to know whether to execute a 
> for-loop with "<" 
> > or a for-loop with ">" (and the code specified in each separate 
> > for-loop has to be written redundantly).  I found this to 
> be awkward.
> 
> What's wrong with
>     for min(start,end) < var < max(start,end)

Nothing at all, but with this syntax you have different semantics for:

   for start <= i < end:

And

   if start <= i < end:

One being an iterative construct, the other being a 'simple' comparison.
I find that at least as confusing as integers producing iterators in
iterative constructs.

Of course, if anyone actually cared about this syntax, we would have a
PEP with a pro/con section, so we wouldn't have to reiterate the same
arguments over and over again <wink>

-- bjorn




More information about the Python-list mailing list