<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
tt
        {mso-style-priority:99;
        font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
span.EstiloCorreo18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:254286933;
        mso-list-type:hybrid;
        mso-list-template-ids:626970370 1593059336 201981977 201981979 201981967 201981977 201981979 201981967 201981977 201981979;}
@list l0:level1
        {mso-level-text:%1>;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=ES link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi Diego,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I don’t know exactly if this could work for you but you can do complex patterns like this to take what you want<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#1F497D'><span style='mso-list:Ignore'>1><span style='font:7.0pt "Times New Roman"'>  </span></span></span><![endif]><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#1F497D'>ets:new(table, [named_table]),<o:p></o:p></span></p><p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#1F497D'><span style='mso-list:Ignore'>2><span style='font:7.0pt "Times New Roman"'>  </span></span></span><![endif]><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#1F497D'>ets:insert(</span><tt><i><span lang=EN-US style='font-size:10.0pt'>"Peter", [{"children", ["Bob", "Paul"]}, {"father", ["Mike"]}]}</span></i></tt><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#1F497D'>),<o:p></o:p></span></p><p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#1F497D'><span style='mso-list:Ignore'>3><span style='font:7.0pt "Times New Roman"'>  </span></span></span><![endif]><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#1F497D'>ets:match(table, {"Peter", [{"children", '$1'},'_'] }).<o:p></o:p></span></p><p class=MsoListParagraph><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>[[["Bob","Paul"]]]<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If you always match against the key, you do really faster.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Bests,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Ivan.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>De:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> erlang-questions-bounces@erlang.org [mailto:erlang-questions-bounces@erlang.org] <b>En nombre de </b>Diego Llarrull<br><b>Enviado el:</b> lunes, 04 de marzo de 2013 14:58<br><b>Para:</b> erlang-questions@erlang.org<br><b>Asunto:</b> [erlang-questions] Nested match specifications?<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>Hello everyone, <br><br>I would like to insert in an ETS table a tuple with the following type signature: <br><br><tt><i><span style='font-size:10.0pt'>{string(), [{string(), [string()]}]}</span></i></tt><br><br>As an example: <br><i><br></i><tt><i><span style='font-size:10.0pt'>{"Peter", [{"children", ["Bob", "Paul"]}, {"father", ["Mike"]}]}</span></i></tt><i><br><br></i><br>My question is the following: is it possible to solve, using match specifications, nested queries like "Retrieve the name of Peter's children" ?<br><br>That is, a query where I would need to <br><br>a) Fetch all ("the", since its a set) tuples of size 3 where "Peter" is located in the first position (doable with MS)<br>b) Let '$2' be the value in the second position of the tuple fetched in a). Then, fetch the value corresponding to the key "children" in '$2', if interpreted as a key-value list (i.e. lists:keyfind() should work on '$2'). <br><br>If I understood correctly, lists:keyfind can't be used inside a match specification because they only allow the BIFs described in <a href="http://www.erlang.org/doc/apps/erts/match_spec.html">http://www.erlang.org/doc/apps/erts/match_spec.html</a>. My question is: is there any low-level mechanism to operate on lists inside match specifications, or am I trying to push the boundaries of match specifications?<br><br>In case anyone wonders "Why not use Query Lists Comprehensions?" the answer is: "Because of performance issues: in our platform, we need to dynamically build QLCs based on the number of arguments that arrive, which forces us to build them as strings and then use qlc:string_to_handle() which is SLOW". <br><br>Any help of insight will be greatly appreciated. Thank you very much in advance. <br><br>Diego Llarrull<br><br> <o:p></o:p></p></div></body></html>