<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'><font face="'Times New Roman'" style="font-family: 'Times New Roman'; ">As Attila has said the way to do this:</font><div style="font-family: 'Times New Roman'; "><br></div><div style="font-family: 'Times New Roman'; "><font face="'courier new', courier, monaco, monospace, sans-serif">handle_cast(#inputmsg{}=Msg, State) -></font></div><div style="font-family: 'Times New Roman'; "><font face="'courier new', courier, monaco, monospace, sans-serif"> ... ;</font></div><div style="font-family: 'Times New Roman'; "><br></div><div><span style="font-family: 'Times New Roman'; ">The reason your example doesn't work is that </span><font face="'courier new', courier, monaco, monospace, sans-serif">#inputmsg{_='_'}</font><font face="'Times New Roman'"> expands so that all the fields will get the value of the ATOM '_' which is definitely not the same as the VARIABLE _. In this case there is actually no need to do anything as the compiler automatically puts the variable _ for all fields which aren't explicitly mentioned.</font></div><div><font face="'Times New Roman'"><br></font></div><div><font face="'Times New Roman'">The main use of the _='_' construct is when you want to create a match pattern for ets/mnesia which is tuple which is INTEPRETED as a pattern. Then it is useful to have a construct which sets all unmentioned fields to the value of the atom '_' which is interpreted as the don't care variable.</font></div><div><font face="'Times New Roman'"><br></font></div><div><font face="'Times New Roman'">It is irrelevant whether you write </font><font face="'courier new', courier, monaco, monospace, sans-serif">#inputmsg{}=Msg</font><font face="'Times New Roman'"> or </font><font face="'courier new', courier, monaco, monospace, sans-serif">Msg=#inputmsg{}</font><font face="'Times New Roman'">, they are equivalent. I prefer the former, but many prefer the latter.</font></div><div><font face="'Times New Roman'"><br></font></div><div><font face="'Times New Roman'">Robert</font></div><div style="font-family: 'Times New Roman'; "><br><hr id="zwchr"><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">Hi,<div>I'm trying to use records in functions pattern matching but I'm not able. I want something like that:<div><br></div><div><div>handle_cast(Msg = #inputmsg{_='_'}, State) -></div><div> do_something(Msg),</div>
<div> {noreply, State};</div></div><div><br></div><div>Any idea?</div><div>thanks.</div></div>
<br>_______________________________________________<br>erlang-questions mailing list<br>erlang-questions@erlang.org<br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote><br></div></div></body></html>