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

Brett Cannon brett at python.org
Mon Jan 19 20:31:33 CET 2009


On Mon, Jan 19, 2009 at 10:03, Gerald Britton <gerald.britton at gmail.com> wrote:
> 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.
>

The reason Python would be harder to learn is there is something more
to learn. Removing confusion for something from the standard library
by adding syntax does not warrant making the language easier.

For something to be considered making the language easier it needs to
solve a very common idiom in a way that is an improvement over the
alternatives. In this instance I don't think the idiom is common
enough to warrant the change.

-Brett


> 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
>>
> _______________________________________________
> 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/brett%40python.org
>


More information about the Python-Dev mailing list