<div dir="ltr">On Tue, May 14, 2013 at 6:01 PM, Janos Hary <span dir="ltr"><<a href="mailto:janos.n.hary@gmail.com" target="_blank">janos.n.hary@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="">
<span style="font-size:10pt;font-family:'Courier New',serif;color:rgb(32,32,32)">Thanks for the answer. As far as I understand it works great if the prefix is known at compile time. I wasn’t clear on this, but in my case the prefix is given in runtime.<u></u><u></u></span></p>
<p class=""><span style="font-size:10pt;font-family:'Courier New',serif;color:rgb(32,32,32)"><u></u></span></p></div></div></blockquote><div><br></div><div style>Yes, literal fun as arg to ets:fun2ms is a compile time entity. It's good for getting the first sketch of match spec in shell. </div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><p class="">
<span style="font-size:10pt;font-family:'Courier New',serif;color:rgb(32,32,32)">So far I come up with this solution. It understands a ‘*’ character at a pattern’s end. I’d be happy to get suggestions to improve it.<u></u><u></u></span></p>
<p class=""><span style="font-size:10pt;font-family:'Courier New',serif;color:rgb(32,32,32)"><u></u> <u></u></span></p><p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas;color:rgb(178,34,34)">%% finds '*' in pattern and return a minimum and maximum pattern</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas;color:rgb(178,34,34)">%% e.g. </span><span style="font-size:10pt;font-family:Consolas;color:rgb(179,106,106)"><<"hello*"></span><span style="font-size:10pt;font-family:Consolas;color:rgb(178,34,34)">> -> {</span><span style="font-size:10pt;font-family:Consolas;color:rgb(179,106,106)"><<"hello"></span><span style="font-size:10pt;font-family:Consolas;color:rgb(178,34,34)">>, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(179,106,106)"><<"hellp"></span><span style="font-size:10pt;font-family:Consolas;color:rgb(178,34,34)">>}</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas;color:rgb(178,34,34)">%% if binary string X starts with 'hello' then </span><span style="font-size:10pt;font-family:Consolas;color:rgb(179,106,106)"><<"hello"></span><span style="font-size:10pt;font-family:Consolas;color:rgb(178,34,34)">> </span><span style="font-size:10pt;font-family:Consolas;color:rgb(179,106,106)"><= X < <<"hellp"></span><span style="font-size:10pt;font-family:Consolas;color:rgb(178,34,34)">></span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas">wildcard(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pattern</span><span style="font-size:10pt;font-family:Consolas">) </span><b><span style="font-size:10pt;font-family:Consolas;color:rgb(160,32,240)">when</span></b><span style="font-size:10pt;font-family:Consolas"> is_binary(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pattern</span><span style="font-size:10pt;font-family:Consolas">) </span><span style="font-size:10pt;font-family:Consolas;color:blue">-></span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> </span><b><span style="font-size:10pt;font-family:Consolas;color:rgb(160,32,240)">case</span></b><span style="font-size:10pt;font-family:Consolas"> binary:match(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pattern</span><span style="font-size:10pt;font-family:Consolas">, <<</span><span style="font-size:10pt;font-family:Consolas;color:rgb(188,143,143)">"*"</span><span style="font-size:10pt;font-family:Consolas">>>) </span><b><span style="font-size:10pt;font-family:Consolas;color:rgb(160,32,240)">of</span></b><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> nomatch </span><span style="font-size:10pt;font-family:Consolas;color:blue">-></span><span style="font-size:10pt;font-family:Consolas"> </span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> {</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pattern</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pattern</span><span style="font-size:10pt;font-family:Consolas">};</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> {</span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">0</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">_</span><span style="font-size:10pt;font-family:Consolas">} </span><span style="font-size:10pt;font-family:Consolas;color:blue">-></span><span style="font-size:10pt;font-family:Consolas"> </span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> {error, wrong_pattern};</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p><p class="" style="text-autospace:none">
<span style="font-size:10pt;font-family:Consolas"> {</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">S</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">_</span><span style="font-size:10pt;font-family:Consolas">} </span><span style="font-size:10pt;font-family:Consolas;color:blue">-></span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatPref</span><span style="font-size:10pt;font-family:Consolas"> = binary:part(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pattern</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">0</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">S</span><span style="font-size:10pt;font-family:Consolas">-</span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">1</span><span style="font-size:10pt;font-family:Consolas">),</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> io:format(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(188,143,143)">"<b>~s</b>"</span><span style="font-size:10pt;font-family:Consolas">, [</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatPref</span><span style="font-size:10pt;font-family:Consolas">]),</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> <<</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatLast</span><span style="font-size:10pt;font-family:Consolas">:</span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">8</span><span style="font-size:10pt;font-family:Consolas">>> = binary:part(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pattern</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">S</span><span style="font-size:10pt;font-family:Consolas">-</span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">1</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">1</span><span style="font-size:10pt;font-family:Consolas">),</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> {<<</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatPref</span><span style="font-size:10pt;font-family:Consolas">/binary, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatLast</span><span style="font-size:10pt;font-family:Consolas">:</span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">8</span><span style="font-size:10pt;font-family:Consolas">>>, <<</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatPref</span><span style="font-size:10pt;font-family:Consolas">/binary, (</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatLast</span><span style="font-size:10pt;font-family:Consolas">+</span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">1</span><span style="font-size:10pt;font-family:Consolas">):</span><span style="font-size:10pt;font-family:Consolas;color:rgb(90,90,180)">8</span><span style="font-size:10pt;font-family:Consolas">>>}</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class=""><span style="font-size:10pt;font-family:Consolas"> </span><b><span style="font-size:10pt;font-family:Consolas;color:rgb(160,32,240)">end</span></b><span style="font-size:10pt;font-family:Consolas">.<u></u><u></u></span></p>
<p class=""><span style="font-size:10pt;font-family:Consolas"><u></u> <u></u></span></p><p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas">find(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pat</span><span style="font-size:10pt;font-family:Consolas">) </span><span style="font-size:10pt;font-family:Consolas;color:blue">-></span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> {</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatMin</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatMax</span><span style="font-size:10pt;font-family:Consolas">} = wildcard(</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Pat</span><span style="font-size:10pt;font-family:Consolas">),</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">F</span><span style="font-size:10pt;font-family:Consolas"> = </span><b><span style="font-size:10pt;font-family:Consolas;color:rgb(160,32,240)">fun</span></b><span style="font-size:10pt;font-family:Consolas">() </span><span style="font-size:10pt;font-family:Consolas;color:blue">-></span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> qlc:eval(qlc:q(</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p><p class="" style="text-autospace:none">
<span style="font-size:10pt;font-family:Consolas"> [</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Patient</span><span style="font-size:10pt;font-family:Consolas"> || #patient{search_name = </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">N</span><span style="font-size:10pt;font-family:Consolas">}=</span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">Patient</span><span style="font-size:10pt;font-family:Consolas"> <- mnesia:table(pat),</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">N</span><span style="font-size:10pt;font-family:Consolas"> >= </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatMin</span><span style="font-size:10pt;font-family:Consolas">, </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">N</span><span style="font-size:10pt;font-family:Consolas"> < </span><span style="font-size:10pt;font-family:Consolas;color:rgb(184,134,11)">PatMax</span><span style="font-size:10pt;font-family:Consolas">]</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="" style="text-autospace:none"><span style="font-size:10pt;font-family:Consolas"> ))</span><span style="font-size:10pt;font-family:Consolas"><u></u><u></u></span></p><p class=""><span style="font-size:10pt;font-family:Consolas"> </span><b><span style="font-size:10pt;font-family:Consolas;color:rgb(160,32,240)">end</span></b><span style="font-size:10pt;font-family:Consolas">,<u></u><u></u></span></p>
<p class=""><span style="font-size:10pt;font-family:Consolas"> mnesia:activity(transaction, F, [], mnesia_frag).<u></u><u></u></span></p><p class=""><span style="font-size:10pt;font-family:Consolas"><u></u></span></p>
</div></blockquote><div><br></div><div style>This is a full scan of the table, and since match spec's first arg can't be a binary with prefix only the full scan can't be avoided.</div><div style>Function you have is pretty much the only way to do what you want.</div>
<div style><br></div><div style>Cheers</div><div style> </div></div></div></div>