Integrated many suggestions from c.l.py and others. Nothing
substantial w.r.t. the proposed solution, just clarifications, additional references, and an explanation of why most syntax changes don't work.
This commit is contained in:
parent
208ff7b554
commit
88002f143d
52
pep-0201.txt
52
pep-0201.txt
|
@ -10,14 +10,14 @@ Post-History: 27-Jul-2000
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
|
|
||||||
This PEP describes the `lockstep iteration' proposal for Python
|
This PEP describes the `lockstep iteration' proposal. This PEP
|
||||||
2.0. This PEP tracks the status and ownership of this feature,
|
tracks the status and ownership of this feature, slated for
|
||||||
slated for introduction in Python 2.0. It contains a description
|
introduction in Python 2.0. It contains a description of the
|
||||||
of the feature and outlines changes necessary to support the
|
feature and outlines changes necessary to support the feature.
|
||||||
feature. This PEP summarizes discussions held in mailing list
|
This PEP summarizes discussions held in mailing list forums, and
|
||||||
forums, and provides URLs for further information, where
|
provides URLs for further information, where appropriate. The CVS
|
||||||
appropriate. The CVS revision history of this file contains the
|
revision history of this file contains the definitive historical
|
||||||
definitive historical record.
|
record.
|
||||||
|
|
||||||
|
|
||||||
Motivation
|
Motivation
|
||||||
|
@ -25,13 +25,17 @@ Motivation
|
||||||
Standard for-loops in Python iterate over every element in a
|
Standard for-loops in Python iterate over every element in a
|
||||||
sequence until the sequence is exhausted[1]. However, for-loops
|
sequence until the sequence is exhausted[1]. However, for-loops
|
||||||
iterate over only a single sequence, and it is often desirable to
|
iterate over only a single sequence, and it is often desirable to
|
||||||
loop over more than one sequence, in a lock-step, "Chinese Menu"
|
loop over more than one sequence in a lock-step fashion. In other
|
||||||
type of way.
|
words, in a way such that nthe i-th iteration through the loop
|
||||||
|
returns an object containing the i-th element from each sequence.
|
||||||
|
|
||||||
The common idioms used to accomplish this are unintuitive and
|
The common idioms used to accomplish this are unintuitive. This
|
||||||
inflexible. This PEP proposes a standard way of performing such
|
PEP proposes a standard way of performing such iterations by
|
||||||
iterations by introducing a new builtin function called `zip'.
|
introducing a new builtin function called `zip'.
|
||||||
|
|
||||||
|
While the primary motivation for zip() comes from lock-step
|
||||||
|
iteration, by implementing zip() as a built-in function, it has
|
||||||
|
additional utility in contexts other than for-loops.
|
||||||
|
|
||||||
Lockstep For-Loops
|
Lockstep For-Loops
|
||||||
|
|
||||||
|
@ -70,13 +74,20 @@ Lockstep For-Loops
|
||||||
[(1, 4), (2, 5), (3, 6), (None, 7)]
|
[(1, 4), (2, 5), (3, 6), (None, 7)]
|
||||||
|
|
||||||
For these reasons, several proposals were floated in the Python
|
For these reasons, several proposals were floated in the Python
|
||||||
2.0 beta time frame for providing a better spelling of lockstep
|
2.0 beta time frame for syntactic support of lockstep for-loops.
|
||||||
for-loops. The initial proposals centered around syntactic
|
Here are two suggestions:
|
||||||
changes to the for statement, but conflicts and problems with the
|
|
||||||
syntax were unresolvable, especially when lockstep for-loops were
|
|
||||||
combined with another proposed feature called `list
|
|
||||||
comprehensions' (see pep-0202.txt).
|
|
||||||
|
|
||||||
|
for x in seq1, y in seq2:
|
||||||
|
# stuff
|
||||||
|
|
||||||
|
for x, y in seq1, seq2:
|
||||||
|
# stuff
|
||||||
|
|
||||||
|
Neither of these forms would work, since they both already mean
|
||||||
|
something in Python and changing the meanings would break existing
|
||||||
|
code. All other suggestions for new syntax suffered the same
|
||||||
|
problem, or were in conflict with other another proposed feature
|
||||||
|
called `list comprehensions' (see pep-0202.txt).
|
||||||
|
|
||||||
The Proposed Solution
|
The Proposed Solution
|
||||||
|
|
||||||
|
@ -206,7 +217,8 @@ References
|
||||||
[1] http://www.python.org/doc/current/ref/for.html
|
[1] http://www.python.org/doc/current/ref/for.html
|
||||||
[2] http://www.haskell.org/onlinereport/standard-prelude.html#$vzip
|
[2] http://www.haskell.org/onlinereport/standard-prelude.html#$vzip
|
||||||
|
|
||||||
TBD: URL to python-dev archives
|
Greg Wilson's questionaire on proposed syntax to some CS grad students
|
||||||
|
http://www.python.org/pipermail/python-dev/2000-July/013139.html
|
||||||
|
|
||||||
|
|
||||||
Copyright
|
Copyright
|
||||||
|
|
Loading…
Reference in New Issue