Erlang is getting too big

Luke Gorrie luke@REDACTED
Tue Oct 14 04:42:29 CEST 2003


Francesco Cesarini <francesco@REDACTED> writes:

> Things such as List (In)Comprehensions are powerful if you know what
> you are doing.

Out of curiosity, what is it you don't like about list comprehensions?
Just one more thing to learn, or do you think they're particularly
confusing in practice even if you've read how they work?

They definitely are one more thing to learn. But assuming you've read
the basics, I think list comprehensions with only one generator are
really easy to understand - just a straight-forward combination of map
and filter.

Initially I found multiple generators difficult to understand, until I
was shown that it's the same thing as nested loops. So:

  [{X,Y} || X <- list1(),
            Y <- list2(),
            test(X, Y)]

is like, in pseudo-code:

  results = empty()
  for X in list1()
    for Y in list2()
      if test(X, Y) then results.add({X, Y})
  return results

with one extra nested loop for each generator. That makes it pretty
understandable for me, even though I rarely find a use for multiple
generators in practice.

Cheers,
Luke




More information about the erlang-questions mailing list