[Python-Dev] PEP 204 (range literals)

Ka-Ping Yee ping@lfw.org
Fri, 8 Mar 2002 03:21:07 -0600 (CST)


After reading the Parade of the PEPs, i looked at PEP 284, which
proposes yet another solution to for-loop iteration over integers.

This caused me to go back and look at all the other proposals for
this problem: PEP 204, PEP 212, PEP 276, and PEP 281.

For me, PEP 204 stands out as the nicest and most straightforward
solution.  My answers to the Open Issues in PEP 204 would be:

    Q. Should [x:y] produce a generator?

    A. Not in the general case.  However, when it appears as a
       literal in a "for" statement, the compiler is free to
       replace it with an xrange object or generator without
       any visible effect (except better performance).


    Q. Should it be possible to mix range syntax with list literals?
       For example, [5, 6, 1:6, 7] becomes [5, 6, 1, 2, 3, 4, 5, 7].

    A. No.


    Q. Should it be possible to concatenate ranges in list comprehensions?
       For example, [x:4 for x in (1, 2)] becomes [1, 2, 3, 2, 3].

    A. No.


    Q. Should range literals accept objects other than integers?
       For example, ['a':'e'] becomes ['a', 'b', 'c', 'd'].

    A. No.

PEP 204 mentions that it was rejected but doesn't provide much
explanation for its rejection; could this be elaborated upon?


-- ?!ng