[erlang-questions] Is it better to use tuple to send the message or list or it just does not matter ?
lang qiu
qiulang@REDACTED
Mon Dec 22 16:45:27 CET 2008
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081222/d16c4cf4/attachment.htm>
More information about the erlang-questions
mailing list