As you mentioned both alternatives work, you can send and receive anything, and as Jacob was alluding to is the general rule that you use a tuple when the size is known and fixed and use a list for dynamic collections. Also for this type of usage a tuple is more efficient both in speed and memory size.<br>
<br>Robert<br><br><div class="gmail_quote">2008/12/22 lang qiu <span dir="ltr"><<a href="mailto:qiulang@gmail.com">qiulang@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>When sending message by <b>Pid ! Message</b>, is it better to use <b>tuple </b>or <b>list </b>or it just does <b>not </b>matter ?<br><br>For example (the area_server0 example in "programming erlang"), <br>

<br>-module(area_server0).<br>-export([loop/0]).<br><br>loop() -><br>   receive<br>      <b>{rectangle, Width, Ht}</b> -> % tuple here<br>          io:format("Area of rectangle is ~p~n" ,[Width * Ht]),<br>

          loop();<br>      {circle, R} -><br>          io:format("Area of circle is ~p~n" , [3.14159 * R * R]),<br>          loop();<br>      Other -><br>          io:format("I don't know what the area of a ~p is ~n" ,[Other]),<br>

          loop()<br>    end.<br><br>Here we uses tuples to send/receive messages, but when I change them to list, the codes still work.<br><br>loop() -><br>
   receive<br>
      <b>[rectangle, Width, Ht]</b> -> <br>      ... % Still works as long as we agree to use list to send the message.<br><br>So I was wondering does this mean either tuple or list is ok or there is still some difference between them ?<br>

<br>Thanks!<br><br>Qiulang<br>     <br>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br>