Re:Kotlin: A Language with a Bright Future
by lmm on Monday November 20, 2017 @10:52AM
(#15740753)
I find Python's list comprehensions unusable because they're backwards from how I'd expect. Thankfully in Scala the syntax is almost exactly the same; you write
for an imperative for loop, and
for the general comprehension. In Python you have to put the equivalent of the yield right at the start, which is just so different from how everything else in the language works.
[ Parent
| on HN ]
Re:Kotlin: A Language with a Bright Future
by kazinator on Monday November 20, 2017 @11:05AM
(#15740878)
Whoever designed the comprehension syntax for Python was perhaps enamored of the "such that" math notation { expr-with-vars | constraint-predicates }.
https://en.wikipedia.org/wiki/Set-builder_notation#Sets_defi...
Re:Kotlin: A Language with a Bright Future
by dmitriid on Monday November 20, 2017 @02:40PM
(#15742557)
I wish they'd leave the math notation as is. Haskell's and Erlang's notations which keep it (maybe with slight modifications) are so much nicer and readable.
Erlang [1]:
[X || X <- [1,2,a,3,4,b,5,6], X > 3].
Pythagorean triplets
[ {A,B,C} ||
A <- lists:seq(1,N),
B <- lists:seq(1,N),
C <- lists:seq(1,N),
A+B+C =< N,
A*A+B*B == C*C
].
[1] http://erlang.org/doc/programming_examples/list_comprehensio...
Re:Kotlin: A Language with a Bright Future
by actsasbuffoon on Monday November 20, 2017 @12:10PM
(#15741400)
That's because Python's list comprehensions were derived from Haskell's implementation: https://wiki.python.org/moin/PythonVsHaskell#List_Comprehens...:
As per https://wiki.haskell.org/List_comprehension , many Haskell users prefer to use do syntax (indeed I wasn't aware that the list comprehension syntax existed).
Re:Kotlin: A Language with a Bright Future
by actsasbuffoon on Monday November 20, 2017 @01:53PM
(#15742158)
Agreed, I never use list comprehensions in Haskell. I feel like they're almost always harder to read.