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>