# [erlang-questions] How to understanding recursive inside comprehension lists?

Sverker Eriksson sverker@REDACTED
Fri Aug 23 15:44:02 CEST 2019

```How to create all permutations of List:
Construct all possible lists [H|T]

where H is one element of List
and T is one of all the permutations of the
remaining elements in List.

And the empty list has one permutation; the empty list.

/Sverker

On fre, 2019-08-23 at 19:03 +0700, I Gusti Ngurah Oka Prinarjaya wrote:
> Hi,
>
> Now I read Joe's book titled Programming Erlang 2nd Edition. I practice some
> functions such as for/3, quicksort/1, pythag/1, and perms/1, and perms/1 is
> the function that hard to understand.
>
> I understand comprehension lists, I fully understand for/3, I fully understand
> quicksort/1, pythag/1. But it's really hard for me to understand perms/1.
> Please teach me how to read and understand this perms/1 function.
>
> perms([]) -> [[]];
> perms(List) -> [ [H|T] || H <- List, T <- perms(List--[H]) ].
>
> Output:
> 1> lib_misc:perms("123").
> ["123","132","213","231","312","321"]
>
>
> Thank you
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED