Range Operation pre-PEP

Bjorn Pettersen BPettersen at NAREX.com
Wed May 9 11:52:46 EDT 2001


> From: Thomas Heller [mailto:thomas.heller at ion-tof.com]
> 
> > > At 12:23 09/05/01 +0200, Alex Martelli wrote:
> > > >Getting beginners used to inclusive-upper-end idioms
> > > >and then having them trip over exclusive-upper-end
> > > >ones elsewhere later is NOT doing them any favour.
> > >
> > > Ok, I'm in brainstorm mode. You're warned :-) Some weird 
> ideas are just
> > > popping out of my mind:
> > >
> for i in [0:10):
>     print i
> 
> for i in [0:10]:
>     print i
> 
> Thomas

If all we want to do is get rid of 

  for i in range(len(seq)):
	...

why not overload range so it can take a sequence directly:

  for i in range(seq):
      ...

If we really want range literals (which I don't see as particularly useful
outside this application although I'm happy to be proven wrong <wink>), we
can't use x:y since Guido has allready nixed it, and we shouldn't use x..y
since the established meaning interfers with common usage leading to
unappealing constructs like 0..len(seq)-1. We could certainly come up with
other syntax, e.g. x -> y meaning from x up to, but not including, y:

  for i in 0 -> len(seq):
      ...

I still favor overloading range though...

-- bjorn




More information about the Python-list mailing list