I'm a Mathematica beginner.
I am exploring the use of patterns and (only for fun) am trying to implement a permutations function.
My (dirty) code is:
permutations[l:{e___}] :=
Module[{f, p},
SetAttributes[f, {Orderless}];
p = Table[Pattern @@ {Unique[], _}, {Length @ l}];
ReplaceList[f[e], f @@ p -> p[[All, 1]]]];
permutations[{a, b, c}]
It returns:
{{a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b}, {c, b, a}}
Have you got a cleaner solution without use of the Unique
?