Wither Self
Joachim Durchholz
joachim.durchholz@REDACTED
Mon Sep 8 15:36:32 CEST 2003
Joe Armstrong wrote:
>
> Shouldn't there be a Self in funs?
>
> IMHO writing:
>
> Fac = fun(0) -> 1;
> (N) -> N*Self(N-1) end
>
> is just teensy weensy bit simpler than:
>
> Fact = fun(X) ->
> G = fun(0, F) -> 1;
> (N, F) -> N*F(N-1,F)
> end,
> G(X, G)
> end.
That's nice, but it doesn't handle mutual recursion.
Personally, I'd prefer a scope construct that first introduces a set of
names, then binds definitions to them.
Syntactically, this need not have an ugly syntax; I'm thinking along
lines like these:
define
Fac = fun/1
0 -> 1;
N -> N * Fac (N - 1)
end
some_constant = 2;
Even = fun/1
0 -> True;
N -> odd (N - 1)
end
Odd = fun/1
1 -> False;
N -> Even (N - 1)
end
end
(I know this is very different from the current fun syntax, more a "how
I'd like it if I could designed it scratch" thing.)
Just my 2c.
Regards,
Jo
More information about the erlang-questions
mailing list