[erlang-questions] Tail recursive tests
Wed May 28 17:52:03 CEST 2008
>From time to time I find that I want to write something like:
foo() -> true;
foo([H|T]) -> bar(H) andalso foo(T).
Which works, but is not tail recursive. Is there any reason why it couldn't be?
Does anyone consider it bad form? I find it clearer than:
case bar(H) of
true -> foo(T);
false -> false
This is *not* another variation of the old "I hate Erlang's case and
if" discussion. I'm only talking about functions that evaluates to a
Here's a more involved example:
search_for_key(<<>>, _, _) ->
search_for_key(B, C, K) ->
delim_char(C) andalso subsearch(B, K)
<<C2, B2/binary>> = B,
search_for_key(B2, C2, K).
More information about the erlang-questions