[erlang-questions] List Comprehensions permutation
contact@REDACTED
contact@REDACTED
Thu Apr 2 21:34:49 CEST 2009
Hi all,
I recently bought the book "Programming Erlang" by Joe Armstrong and I
have a little problem of comprehension about the logical of an
algorithm.
Here is the sample from the book :
perms([]) -> [[]];
perms(L) ->
[[H|T] || H <- L, T <- perms(L--[H])].
I would like to know why we return [[]] and not [] ?
I have try some tests :
6> [[H|T] || H <- [1], T <- []].
[]
7> [[H|T] || H <- [1], T <- [[]]].
[[1]]
For me it's not logical, in my brain its should be something like :
8> [1|[]].
[1]
9> [1|[[]]].
[1,[]]
(all the sample are paste from erlang shell).
Someone can "light" me about this ?
Thanks in advance.
More information about the erlang-questions
mailing list