[erlang-questions] re cursive fun()
Tue Oct 7 16:29:18 CEST 2008
On Tuesday, October 07, 2008, Hynek Vychodil wrote:
> Is there any problem write this think this way?
. . .
> For Example factorial:
> Fact = begin F = fun(_, 0) -> 1; (Self, N) -> Self(Self, N-1)*N end,
fun(N) -> F(F, N) end end.
My only objection is that it pollutes the shell variable space with the
extra function F. How about:
Fact = fun(N) -> F = fun(_, 0) -> 1; (Self, N) -> Self(Self, N-1)*N end,
F(F, N) end.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions