How to test for missing tail recursive calls in service loops?

Magnus Henoch magnus@REDACTED
Fri Sep 25 22:26:25 CEST 2009

Jeremy Raymond <jeraymond@REDACTED> writes:

> If a service loop is missing a tail recursive call in a receive clause then
> the first time a message is sent to the process matching the bad clause the
> call the receive succeeds. However subsequent calls will fail as the process
> is no longer waiting on a receive due to the missing tail recursive call. Is
> there a good way to test for this error besides just make multiple calls to
> the service matching the same clause? Is there some way to interrogate the
> process to see if it's currently waiting on a receive?

typer comes to mind.

This is my foo.erl.  Note that foo/0 does a proper tail call, but I
forgot to make bar/0 do the same.


foo() ->
        foo ->
        stop ->
            {ok, done}

bar() ->
        bar ->
        stop ->
            {ok, done}

Let's run typer on it:

$ typer foo.erl

%% File: "foo.erl"
%% ---------------
-spec foo() -> {'ok','done'}.
-spec bar() -> 'true' | {'ok','done'}.

Here we see that foo/0 always returns {ok, done}, but bar/0 sometimes
returns true - that's our warning signal.

Magnus Henoch, magnus@REDACTED
Erlang Training and Consulting

More information about the erlang-questions mailing list