Wither Self

Richard A. O'Keefe ok@REDACTED
Tue Sep 9 01:55:00 CEST 2003

Joe Armstrong <joe@REDACTED> wrote:
	    Shouldn't there be a Self in funs?
		Fac = fun(0) -> 1;	
			 (N) -> N*Self(N-1) end
Well, if the compiler were just a touch smarter, you wouldn't need it.

If you have
    <pattern> = ... <fun> ...
then the check for unbound variables in <fun> should ask whether
any variable will still be unbound *after* the pattern is matched
instead of whether any variable is unbound *before* the pattern match.

Then you could just write

	Fac = fun(0) -> 1; N -> N * Fac(N-1) end,

without needing Self.  This would also handle mutual recursion:

    {Even, Odd} =
        {fun(0) -> true;  (N) -> Odd( N-1) end,
         fun(0) -> false; (N) -> Even(N-1) end},

which the Self proposal would not deal with at all.

More information about the erlang-questions mailing list