[Python-Dev] The `for y in [x]` idiom in comprehensions

Nick Coghlan ncoghlan at gmail.com
Mon Feb 26 16:27:45 EST 2018


On 27 February 2018 at 05:08, Guido van Rossum <guido at python.org> wrote:

> I would like to remind all wannabe language designers that grammar design
> is not just solving puzzles. It's also about keeping the overall feel of
> the language readable. I'm getting the idea that none of the proposals
> discussed so far (whether new syntax or clever use of existing syntax)
> satisfy that constraint. Sometimes a for-loop is just better.
>

+1

This is the main reason PEP 3150 (which adds a more limited form of
statement local named subexpressions) has spent more time Deferred than it
has ever being discussed as an active draft proposal: while naming
subexpressions is an occasionally attractive prospect, it's also an
addition that has significant potential to change the way various kinds of
code is typically written (even more so than something like type hints or
f-strings).

When even a PEP's author is thinking "I'm not sure this will actually be a
net improvement to the language", it's really not a good sign :)

Cheers,
Nick.

P.S. The comprehension-centric variants at least have the virtue of
precedent in Haskell's "let" clauses:
https://stackoverflow.com/questions/6067839/haskell-let-where-equivalent-within-list-comprehension/6067878#6067878

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180227/3bb01884/attachment.html>


More information about the Python-Dev mailing list