[Python-ideas] Statements vs Expressions... why?

Josiah Carlson josiah.carlson at gmail.com
Sun Sep 14 21:36:17 CEST 2008


On Sun, Sep 14, 2008 at 11:28 AM, Arnaud Delobelle
<arnodel at googlemail.com> wrote:
>
> On 14 Sep 2008, at 10:25, Cliff Wells wrote:
>
>>> Now say you want to write that inline with a for-expression:
>>>
>>>    '-'.join(
>>>        for J in I:
>>>            for j in J:
>>>                YIELD j
>>>        )
>>>
>>> That won't work because the j's will be accumulated in the inner loop
>>> and the outer loop won't accumulate anything, therefore returning an
>>> empty iterable.
>>
>> How about this way instead (since for-loop is now an expression):
>>
>> '-'.join(
>>   for j in ( for J in I: YIELD J ): YIELD j
>> )
>
> After you've had a good night's sleep and when you look at this again,
> you'll definitely think that you were too hasty in replying :)

Agreed.  For all of the semantic and syntactic gymnastics and
discussion about how statements -> expressions would make Python a
better language, all I can conclude from the above is "I'm glad Python
doesn't do that."

 - Josiah



More information about the Python-ideas mailing list