[erlang-questions] Is it better to use tuple to send the message or list or it just does not matter ?

Jacob Torrey discipleofranok@REDACTED
Mon Dec 22 16:56:13 CET 2008


I would recommend using tuples, since the messages are of a fixed length
and format. Only use lists when you are send variable length data, like
a list of users for example.

Jacob

lang qiu wrote:
> Hi all,
> When sending message by *Pid ! Message*, is it better to use *tuple *or
> *list *or it just does *not *matter ?
> 
> For example (the area_server0 example in "programming erlang"),
> 
> -module(area_server0).
> -export([loop/0]).
> 
> loop() ->
>    receive
>       *{rectangle, Width, Ht}* -> % tuple here
>           io:format("Area of rectangle is ~p~n" ,[Width * Ht]),
>           loop();
>       {circle, R} ->
>           io:format("Area of circle is ~p~n" , [3.14159 * R * R]),
>           loop();
>       Other ->
>           io:format("I don't know what the area of a ~p is ~n" ,[Other]),
>           loop()
>     end.
> 
> Here we uses tuples to send/receive messages, but when I change them to
> list, the codes still work.
> 
> loop() ->
>    receive
>       *[rectangle, Width, Ht]* ->
>       ... % Still works as long as we agree to use list to send the message.
> 
> So I was wondering does this mean either tuple or list is ok or there is
> still some difference between them ?
> 
> Thanks!
> 
> Qiulang
>     
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list