[erlang-questions] Why does fun2ms produce this particular result?

Mazen Harake <>
Mon May 2 08:35:08 CEST 2011


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.

http://www.erlang-factory.com/conference/testingtutorialworkshop2010/speakers/MazenHarake

Dbg matchspecs aren't exactly like the mnesia ones, there is a small
difference but the concept is exactly the same.

/M

On 1 May 2011 21:06, Daniel Dormont <> wrote:

> 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:
>
> 1> rd(person, {name, address, email, phone}).
> person
> 2> ets:fun2ms(fun(#person{name=Name, email=Email}) -> {Name, Email}
> end).
> [{#person{name = '$1',address = '_',email = '$2',
>           phone = '_'},
>   [],
>   [{{'$1','$2'}}]}]
>
> 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'}}]
>
> 1) Why is it a list at all, since a particular head in the function can
> only have one result?
> 2) Why does the tuple have to be wrapped in another tuple? ie why isn't it
> just {'$1','$2'}
>
> For now I'm happy to just trust that fun2ms works, but I'd like to
> understand it a little better.
>
> thanks,
> Dan
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110502/411d6d42/attachment.html>


More information about the erlang-questions mailing list