[erlang-questions] Lists Comprehension issue?
Duan, Xiande
xiande.duan@REDACTED
Wed Jan 14 07:08:51 CET 2015
The “L” must be a list of list. Like:
1> L = [[1,2,3],[a,b,c]].
[[1,2,3],[a,b,c]]
2> [X || L1 <- L, X <- L1].
[1,2,3,a,b,c]
3>
From: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Carlos Suarez Fontalvo
Sent: Wednesday, January 14, 2015 1:06 PM
To: erlang-questions@REDACTED
Subject: [erlang-questions] Lists Comprehension issue?
Hi. I've reading this documentation: http://www.erlang.org/doc/programming_examples/list_comprehensions.html
And it says that
3.5 Simplifications with List Comprehensions
As an example, list comprehensions can be used to simplify some of the functions in lists.erl:
append(L) -> [X || L1 <- L, X <- L1].
map(Fun, L) -> [Fun(X) || X <- L].
filter(Pred, L) -> [X || X <- L, Pred(X)].
However when I tried to test this first example "append" doing something simple like this:
73> [X || L1 <- 20, X <- L1].
** exception error: bad generator 20
I got a "exception error" message. Any idea why?. Am I not considering something?
Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150114/b7b38229/attachment.htm>
More information about the erlang-questions
mailing list