Range Operation pre-PEP

Thomas Wouters thomas at xs4all.net
Tue May 8 16:17:15 CEST 2001


On Tue, May 08, 2001 at 11:44:20AM +0400, Roman Suzi wrote:

> What is below is a half-baked proposal for new built-in
> Python operation. If anybody wants to raise this flag 
> again and fill gaps, please do so.

> (I have not studied PEP howto much, so probably I missed
> something important.)

Just one thing: you should send it to Barry (barry at wooz.org) at least if you
want it submitted as a real PEP :)

> I hope the idea of ".." is quite simple: make special syntactic 
> form for xrange (range). I am not into C to reference-implement this
> feature, so if anybody could do it...

It's not too hard to do, though the syntax might require some fiddling. (the
'.' is currently eaten by the tokenizer as part of the number.) I could do
it myself, but I'm so busy right now, I think Tim has more time than I do
<0.4 wink>

>     The proposed implementation uses new syntactic 
>     entity to specify range operation, as shown below:

>         >>> for i in 1 .. 5:
>         ...     print i
>         1
>         2
>         3
>         4
>         5

I like, though the endpoint is debatable. Maybe Greg W. wants to do some
usage testing ? :)

>     Or in extended form to specify a step:

>         >>> for i in (1, 3) .. 5:
>         ...     print i
>         1
>         3
>         5

I don't like this. If anything, it should be the other way 'round 
("1 .. (5, 3)") but even better would be something more obvious, such as 

(1 .. 5) % 3

>     The new operation ".." generates xrange object
>     on by following rule:

I'd suggest it create an Iterator rather than an xrange object. Iterators
are new in the CVS tree, and will be in Python 2.2. Very neat things ;)


>     There are no implicit forms of "..", that is, a1 and an must
>     be present.

If .. created an iterator, it could be open-ended instead.

> Open issues

How about ranges of longs ? floats ? strings ? How about mixed types ? 

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list