[erlang-questions] tail recursion

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Thu May 31 13:32:28 CEST 2007


 
Joe Armstrong wrote:
> 
> Why not just
> 
>   server({X, Y} = State) ->
>      receive
>              {update, NewState} ->
>                  NewState;
>              {x, Client} ->
>                  Client ! X,
>                  server(State);
>              {y, Client} ->
>                  Client ! Y,
>                  sever(State)
>     end.

Besides the fact that there are two bugs in your
program? (*) (:

Oh, I don't know. A logical next step might be to
break out the logic into a separate function, 
similar to handle_call(Request, From, State) in 
gen_server. This is easier with my version.
But either version is fine.

BR,
Ulf W


(*) (1) no recursive call in the first clause
    (2) typo in the server/1 call in the third.
    The compiler would of course catch (2).




More information about the erlang-questions mailing list