diff --git a/pep-0201.txt b/pep-0201.txt index 8e9108561..f9bf4ea18 100644 --- a/pep-0201.txt +++ b/pep-0201.txt @@ -10,14 +10,14 @@ Post-History: 27-Jul-2000 Introduction - This PEP describes the `lockstep iteration' proposal for Python - 2.0. This PEP tracks the status and ownership of this feature, - slated for introduction in Python 2.0. It contains a description - of the feature and outlines changes necessary to support the - feature. This PEP summarizes discussions held in mailing list - forums, and provides URLs for further information, where - appropriate. The CVS revision history of this file contains the - definitive historical record. + This PEP describes the `lockstep iteration' proposal. This PEP + tracks the status and ownership of this feature, slated for + introduction in Python 2.0. It contains a description of the + feature and outlines changes necessary to support the feature. + This PEP summarizes discussions held in mailing list forums, and + provides URLs for further information, where appropriate. The CVS + revision history of this file contains the definitive historical + record. Motivation @@ -25,13 +25,17 @@ Motivation Standard for-loops in Python iterate over every element in a sequence until the sequence is exhausted[1]. However, for-loops iterate over only a single sequence, and it is often desirable to - loop over more than one sequence, in a lock-step, "Chinese Menu" - type of way. + loop over more than one sequence in a lock-step fashion. In other + 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 - inflexible. This PEP proposes a standard way of performing such - iterations by introducing a new builtin function called `zip'. + The common idioms used to accomplish this are unintuitive. This + PEP proposes a standard way of performing such iterations by + 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 @@ -70,13 +74,20 @@ Lockstep For-Loops [(1, 4), (2, 5), (3, 6), (None, 7)] For these reasons, several proposals were floated in the Python - 2.0 beta time frame for providing a better spelling of lockstep - for-loops. The initial proposals centered around syntactic - 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). + 2.0 beta time frame for syntactic support of lockstep for-loops. + Here are two suggestions: + 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 @@ -206,7 +217,8 @@ References [1] http://www.python.org/doc/current/ref/for.html [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