The Erlang shell evaluates expressions. Calling an anonymous function by itself is a bit tricky. The easy way to do it is to pass in the reference to the function as one of its arguments. Variable binding by pattern matching happens only after a function gets defined. So we cannot call the function by the variable name from within itself.

In the example the D(L) displays the elements in the list L.

1> D = fun(F, []) -> ok;
1>        (F, [H|T]) -> io:format("~p~n", [H]), F(F,T) end.
2> D(D, [a,b,c]).                               

If the binding takes place before the function definition, we could have written like:

1> G = fun([]) -> ok;
1>        ([H|T]) -> io:format("~p~n", [H]), G(T) end.
* 2: variable 'G' is unbound

but, we can see that it gives an error.