[Python-Dev] RE: list comprehensions (was parsers and compilers for 2.0)

Tim Peters tim_one@email.msn.com
Sat, 12 Aug 2000 21:33:43 -0400


[ESR, responding to

  [(x, y) for y in something for x in somewhere if y in x]

 for list comprehension syntax:
]
> Damn.  That's unfortunate.  With all due respect to the BDFL, I've come
> to believe that having special syntax for this (rather than constructor
> functions a la zip()) is a bad mistake.  I predict it's going to come
> back to bite us hard in the future.

[Mark Hammond]
> FWIW, these are my thoughts exactly (for this particular issue,
> anyway).
>
> Wont-bother-voting-cos-nobody-is-counting ly,

Counting, no; listening, yes; persuaded, no.  List comprehensions are one of
the best-loved features of Haskell (really!), and Greg/Skip/Ping's patch
implements as an exact a parallel to Haskell's syntax and semantics as is
possible in Python.  Predictions of doom thus need to make a plausible case
for why a rousing success in Haskell is going to be a disaster in Python.
The only basis I can see for such a claim (and I have to make one up myself
because nobody else has <wink>) is that Haskell is lazy, while Python is
eager.  I can't get from there to "disaster", though, or even "plausible
regret".

Beyond that, Guido dislikes the way Lisp spells most things, so it's this or
nothing.  I'm certain I'll use it, and with joy.  Do an update and try it.

C:\Code\python\dist\src\PCbuild>python
Python 2.0b1 (#0, Aug 12 2000, 14:57:27) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Copyright 1995-2000 Corporation for National Research Initiatives (CNRI)
>>> [x**2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> [x**2 for x in range(10) if x & 1]
[1, 9, 25, 49, 81]
>>> [x**2 if 3]
[81]
>>>

Now even as a fan, I'll admit that last line sucks <wink>.

bug-in-the-grammar-ly y'rs  - tim