In the example the
D(L)
displays the elements in the list L
.1> D = fun(F, []) -> ok;If the binding takes place before the function definition, we could have written like
1> (F, [H|T]) -> io:format("~p~n", [H]), F(F,T) end.
#Fun<erl_eval.12.82930912>
2> D(D, [a,b,c]).
a
b
c
ok
1> G = fun([]) -> ok;but, we can see that it gives an error. This is similar to a fixed-point combinator like a Y combinator.
1> ([H|T]) -> io:format("~p~n", [H]), G(T) end.
* 2: variable 'G' is unbound