[erlang-questions] re cursive fun()
David Mercer
dmercer@REDACTED
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.
Cheers,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081007/a5034993/attachment.htm>
More information about the erlang-questions
mailing list