[Python-Dev] PEP 3142: Add a "while" clause to generator expressions

Gerald Britton gerald.britton at gmail.com
Mon Jan 19 19:03:47 CET 2009


Duly noted and thanks for the feedback!  (just what I was looking for
actually).  I do disagree with the idea that the proposal, if
implemented, would make Python harder to learn.  Not sure who would
find it harder.  Having to find and use takewhile was harder for me.
I still find that one counter-intuitive.  I would have expected the
parameters in the reverse order (take something, while something else
is true).  Tripped me up a few times, which got me thinking about an
alternative.

On Mon, Jan 19, 2009 at 12:51 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> Gerald Britton wrote:
>>
>> Please find below PEP 3142: Add a "while" clause to generator
>> expressions.  I'm looking for feedback and discussion.
>
> This was already discussed on python-ideas where it got negative feedback.
>
> One objection, mentioned by Mathias Panzerbock and Georg Brandl, is that it
> is redundant with takewhile().  You did mention that in the PEP.
>
> The other, posted by Steven Bethard, is that it fundamentally breaks the
> current semantics of abbreviating (except for iteration variable scoping) an
> 'equivalent' for loop.  This should have been listed in the PEP under
> Objections (or whatever the section.  I did not bother to second his
> objection there but will now.
>
> -1
>
> Steven summary:
> "I'm probably just repeating myself here, but the reason not to do it
> is that the current generator expressions translate almost directly
> into the corresponding generator statements. Using "while" in the way
> you've suggested breaks this symmetry, and would make Python harder to
> learn."
>
> Longer presentation:
> "I think this could end up being confusing. Current generator
> expressions turn into an equivalent generator function by simply
> indenting the clauses and adding a yield, for example:
>
>    (i for i in range(100) if i % 2 == 0)
>
> is equivalent to:
>
>    def gen():
>        for i in range(100):
>            if i % 2 == 0:
>                yield i
>
> Now you're proposing syntax that would no longer work like this.
> Taking your example:
>
>    (i for i in range(100) while i <= 50)
>
> I would expect this to mean:
> [meaning, one would expect this to mean, using current rules = tjr]
>
>    def gen():
>        for i in range(100):
>            while i <= 50:
>                yield i
>
> In short, -1. You're proposing to use an existing keyword in a new way
> that doesn't match how generator expressions are evaluated."
>
> Terry Jan Reedy
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/gerald.britton%40gmail.com
>


More information about the Python-Dev mailing list