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

Jayson Vantuyl kagato@REDACTED
Fri Sep 25 22:31:19 CEST 2009


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







More information about the erlang-questions mailing list