Wither Self
Vladimir Sekissov
svg@REDACTED
Mon Sep 8 16:29:46 CEST 2003
Good day,
joe>
joe>
joe> Shouldn't there be a Self in funs?
joe>
joe> IMHO writing:
joe>
joe> Fac = fun(0) -> 1;
joe> (N) -> N*Self(N-1) end
joe>
joe> is just teensy weensy bit simpler than:
joe>
joe> Fact = fun(X) ->
joe> G = fun(0, F) -> 1;
joe> (N, F) -> N*F(N-1,F)
joe> end,
joe> G(X, G)
joe> end.
It would be very nice. For now this natural from user point of view
code could be down only with some tricks:
-define(lambda(Name, Arg, Body), y(fun (Name) -> fun Arg -> Body end end)).
y(X) ->
F = fun (P) -> X(fun (Arg) -> (P(P))(Arg) end) end,
F(F).
test() ->
Fact =
?lambda(Fact, (N),
if (N == 0) -> 1;
true -> N * Fact(N-1)
end
).
Best Regards,
Vladimir Sekissov
More information about the erlang-questions
mailing list