<div dir="ltr">This will do instead<div><br></div><div><div>1> X = [a, b, c].</div><div>[a,b,c]</div><div>2> Y = [a, b, c, d].</div><div>[a,b,c,d]</div><div>3> X == lists:sublist(Y, length(X)).</div><div>true</div>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 17, 2013 at 2:08 PM, Olav Frengstad <span dir="ltr"><<a href="mailto:olav@fwt.no" target="_blank">olav@fwt.no</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hey Ivan,<div><br></div><div>Please correct me if I'm wrong, but when composing the match from an existing variable AFAIK there is no other way:</div><div><br></div><div><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="HOEnZb"><div class="h5"><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><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><a href="tel:%2B47%20920%2042%20090" value="+4792042090" target="_blank">+47 920 42 090</a></div>
</div>
</div></div><br>_______________________________________________<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" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>