Thanks, let me summarize to see if this is correct:<br><br>1) In general (though not in the case of ETS/Mnesia), the MatchBody might contain actions to be performed before returning the final result. This is why it's a list.<br>
2) Actions may be specified in the form of a tuple, the first element of which describes the action to be performed. Therefore, if you want to have your "action" be a value which is itself a tuple, you have to wrap it in another tuple.<br>
<br>Is this right? If so, I guess I understand what the rules are, but I'm still not really clear on why, since it seems like dbg and ets are different enough that you'd never really use the same kind of MatchSpec for both, so there isn't much benefit in having the structure be compatible.<br>
<br>dan<br><br><div class="gmail_quote">On Mon, May 2, 2011 at 2:35 AM, Mazen Harake <span dir="ltr"><<a href="mailto:mazen.harake@gmail.com">mazen.harake@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Check out chapter 2 in my dbg tutorial, it describes matchspecs and how
to use them. You will also understand what it is that fun2ms actually
translates to.<br><br><a href="http://www.erlang-factory.com/conference/testingtutorialworkshop2010/speakers/MazenHarake" target="_blank">http://www.erlang-factory.com/conference/testingtutorialworkshop2010/speakers/MazenHarake</a><br>
<br>Dbg matchspecs aren't exactly like the mnesia ones, there is a small difference but the concept is exactly the same.<br><br>/M<br><br></div><div class="gmail_quote"><div class="im">On 1 May 2011 21:06, Daniel Dormont <span dir="ltr"><<a href="mailto:dan@greywallsoftware.com" target="_blank">dan@greywallsoftware.com</a>></span> wrote:<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">I'm trying to get the hang of match specs. Here's a pretty simple one but it has a feature I'm not getting. It's intended for use with Mnesia:<br>
<br>1> rd(person, {name, address, email, phone}).<br>person<br>
2> ets:fun2ms(fun(#person{name=Name, email=Email}) -> {Name, Email} end). <br>[{#person{name = '$1',address = '_',email = '$2',<br> phone = '_'},<br>
[],<br> [{{'$1','$2'}}]}]<br><br>My first question was going to be why the whole thing is a single-element list, but I think I figured that out: it's because there could be multiple clauses of the match as a whole. The part I don't get is in the result: [{{'$1','$2'}}]<br>
<br>1) Why is it a list at all, since a particular head in the function can only have one result?<br>2) Why does the tuple have to be wrapped in another tuple? ie why isn't it just {'$1','$2'}<br><br>
For now I'm happy to just trust that fun2ms works, but I'd like to understand it a little better.<br>
<br>thanks,<br>Dan<br><br>
<br></div></div><div class="im">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">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></div></blockquote></div><br>
</blockquote></div><br>