How do you write a fun that’s recursive in Erlang?
Since OTP 17.0 there are named funs: 1> Perms = fun F([]) -> [[]]; F(L) -> [[H|T] || H <- L, T <- F(L–[H])] end. #Fun<erl_eval.30.54118792> 2> Perms([a,b,c]). [[a,b,c],[a,c,b],[b,a,c],[b,c,a],[c,a,b],[c,b,a]] Before that you could do this with a little argument trick: 1> Foo = fun(F, X) -> F(F, X) end. #Fun<erl_eval.12.113037538> 2> Foo(Foo, a). <…infinite loop!> … Read more