<div dir="ltr">Hey Ivan,<div><br></div><div style>Please correct me if I'm wrong, but when composing the match from an existing variable AFAIK there is no other way:</div><div style><br></div><div style><div>1> X = [a, b, c].</div>
<div>[a,b,c]</div><div>2> [X | _] = [a, b, c, d].</div><div>** exception error: no match of right hand side value [a,b,c,d]</div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/4/17 Ivan Carmenates García <span dir="ltr"><<a href="mailto:co7eb@frcuba.co.cu" target="_blank">co7eb@frcuba.co.cu</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="ES" link="blue" vlink="purple"><div><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Greetings Olav,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I don’t understand why you try to math using that kind pattern, you can use the common way.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Instead of using ([0,1,2] ++ _) = [0,1,2,3,4] you can use [0,1,2| _] = [0,1,2,3,4] pattern matching.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Best,<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Ivan.<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">De:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:erlang-questions-bounces@erlang.org" target="_blank">erlang-questions-bounces@erlang.org</a> [mailto:<a href="mailto:erlang-questions-bounces@erlang.org" target="_blank">erlang-questions-bounces@erlang.org</a>] <b>En nombre de </b>Olav Frengstad<br>
<b>Enviado el:</b> miércoles, 17 de abril de 2013 16:27<br><b>Para:</b> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a> Questions<br><b>Asunto:</b> [erlang-questions] Wildcard matching a list of strings vs atoms/binaries<u></u><u></u></span></p>
<div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">Hey,<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">I'm getting some unexpected behavior when trying to pattern match the head of a list.<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">When matching against a list of integers I can successfully do a wildcard match:<u></u><u></u></p></div><div><p class="MsoNormal">27> ("ab ++ _) = "abcd".<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">But when trying to do the same with a list of atoms i get the error: * 1: illegal pattern:<u></u><u></u></p></div><div><div><p class="MsoNormal">
28> ([a,b,c] ++ _) = [a,b,c,d].<u></u><u></u></p></div><div><p class="MsoNormal">* 1: illegal pattern<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">So just making sure there's no magic in string matching i also try with an actual list of integers:<u></u><u></u></p>
</div></div><div><div><p class="MsoNormal">29> ([0,1,2] ++ _) = [0,1,2,3,4]. <u></u><u></u></p></div><div><p class="MsoNormal">[0,1,2,3,4]<u></u><u></u></p></div></div><div><p class="MsoNormal"><u></u> <u></u></p></div>
<div><p class="MsoNormal">Why can't I pattern match a lists with other values integers?<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">What i'm looking to achieve is to provide wildcard matching on a gen_event handler so I can do matches like this:<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">handle_event((Match ++ _), State#state{match = Match}) -><u></u><u></u></p></div><div><p class="MsoNormal">% handle<u></u><u></u></p></div>
<div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Any other alternatives is appreciated, current implementation uses lists:suffix/2<u></u><u></u></p></div><div><div><p class="MsoNormal"><u></u> <u></u></p>
</div><p class="MsoNormal">-- <br>Med Vennlig Hilsen<u></u><u></u></p><div><p class="MsoNormal">Olav Frengstad<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Systemutvikler // FWT<u></u><u></u></p>
</div><div><p class="MsoNormal"><a href="tel:%2B47%20920%2042%20090" value="+4792042090" target="_blank">+47 920 42 090</a><u></u><u></u></p></div></div></div></div></div></div></div></blockquote></div><br><br clear="all">
<div><br></div>-- <br>Med Vennlig Hilsen<div>Olav Frengstad</div><div><br></div><div>Systemutvikler // FWT</div><div>+47 920 42 090</div>
</div>