[erlang-questions] How to test for missing tail recursive calls in service loops?

Jeremy Raymond jeraymond@REDACTED
Sun Sep 27 00:12:42 CEST 2009


Oh man, I was hoping for a good mind-reading solution. Thanks both for your
suggestions. I'll try the function idea and give typer a look.

On Fri, Sep 25, 2009 at 4:31 PM, Jayson Vantuyl <kagato@REDACTED> wrote:

> You can implement the "work" part of the loop in a function, then wrap the
> whole thing in a process that always tail-recurses (and use exit() to exit
> the process).  That way you just write your function like it's going to
> loop, and it does.
>
> Or, you can just use gen_server, which does something effectively like this
> (it calls you and loops for you).
>
> In general, though, there's not really a way to detect this, as there are
> plenty of normal "termination conditions" where a process should
> legitimately exit instead of recursing.  Unfortunately, it's a compiler, not
> a mind-reader.  :(
>
>
> On Sep 25, 2009, at 1:11 PM, Jeremy Raymond wrote:
>
>  Hello,
>>
>> 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?
>>
>>
>> Thanks,
>>
>> Jeremy
>>
>
>
> --
> Jayson Vantuyl
> kagato@REDACTED
>
>
>
>
>
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list