List Comprehension Syntax

LittleDanEhren at yahoo.com LittleDanEhren at yahoo.com
Mon Jul 12 17:57:16 CEST 2004


>Luckily, the underlying model of LCs is very well understood (map &
>filter), and solving things the list-processing way is a time-honed
>practice. In the "amaze your friends" front, LCs are more in the "look
>how elegant and concise this can be" genre, not in the "check this
>out, all recursion and no variables, I bet you can't get it even after
>staring it for 5 minutes" genre loved by some academics.

I'd like to point out that list comprehensions were invented by people
who you'd probably put in that genre of academics, namely the creators
of Haskell. I don't really list comprehensions because the syntax is
too specific. In Kogut, a functional language that you'd probably
dismiss as being made by academics because it's functional, the syntax
for the original list comprehension at the beginning of the thread
would be
let result = Filter list ?elem {Part elem 0 4 == "blah"}
->Map (ReplacePart _ "moof" 0 4)
This syntax is very conducive to splitting up into multiple lines and
doesn't require much more explanation than list comprehensions do.  I
really hate it when people say that academics are making programming
languages that are really hard to read; it reflects on the speaker's
stupidity more than anything else.

Daniel Ehrenberg




More information about the Python-list mailing list