<div dir="ltr"><div><br></div><div><br></div><div>Thank you all for the detailed explanation, I guess I was trying to use  "C/C++" way of thinking to understand <record>. </div><div><br></div><div>Br,</div><div>Alex</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-11-08 15:41 GMT+01:00 Raimo Niskanen <span dir="ltr"><<a href="mailto:raimo+erlang-questions@erix.ericsson.se" target="_blank">raimo+erlang-questions@erix.ericsson.se</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Nov 08, 2016 at 02:12:35PM +0100, Alex Feng wrote:<br>
</span><span class="">> Hi,<br>
><br>
> Does anyone know why erlang has to attach the record's name to be able to<br>
> access an attribute ?<br>
> I don't understand, for example, the record "#robot" has been assigned to<br>
> variable "Crusher", why do we have to use  "Crusher#robot.hobbies" instead<br>
> of "Crusher.hobbies" ?<br>
<br>
</span>Records is a compile time syntactical sugar on tagged tuples.<br>
<br>
So "Crusher#robot.hobbies" is translated to something like<br>
  begin robot = element(1, Crusher), element(3, Crusher) end<br>
if 'hobbies' is the second element of #robot.<br>
<br>
The compiler can not know that it is the hobbies field from the #robot<br>
record you want to extract unless told so.  You may mean the hobbies field<br>
from the #whatever record.  It could see that it is a #robot record from an<br>
earlier assignment in the same code and warn about it if it's not,<br>
but in the general case it can not know what is stored in the variable<br>
hence leaves it to be solved in runtime.<br>
<span class=""><br>
<br>
><br>
><br>
> 5> Crusher = #robot{name="Crusher", hobbies=["Crushing people","petting<br>
> cats"]}.<br>
> #robot{name = "Crusher",type = industrial,<br>
> hobbies = ["Crushing people","petting cats"],<br>
> details = []}<br>
> 6> Crusher#robot.hobbies.<br>
> ["Crushing people","petting cats"]<br>
><br>
><br>
> Br,<br>
> Alex<br>
<br>
</span><span class="">> ______________________________<wbr>_________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br>
<br>
--<br>
<br>
</span>/ Raimo Niskanen, Erlang/OTP, Ericsson AB<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>