<div dir="ltr">Ok I got it, your example was missing an external tuple:<div><br></div><div><font face="monospace">ets:select(my_table, [{<br> {Name, '$2', '$3', '$4', '_', '_'},<br> [],<br> [{{{const, Name}, '$2', '$3', '$4'}}]<br>}]).</font><br></div><div><br></div><div>Thank you,</div><div>r.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 10, 2020 at 5:17 PM Roberto Ostinelli <<a href="mailto:ostinelli@gmail.com">ostinelli@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thank you Jacob,<div>I already tried a couple of combinations with const but I always got an error message. For instance:</div><div><br></div><div><font face="monospace">(<a href="mailto:r@127.0.0.1" target="_blank">r@127.0.0.1</a>)2> Name = test.<br></font></div><div><font face="monospace">test</font></div><div><font face="monospace">(<a href="mailto:r@127.0.0.1" target="_blank">r@127.0.0.1</a>)3> ets:select(my_table, [{<br>(<a href="mailto:r@127.0.0.1" target="_blank">r@127.0.0.1</a>)3> {Name, '$2', '$3', '$4', '_', '_'},<br>(<a href="mailto:r@127.0.0.1" target="_blank">r@127.0.0.1</a>)3> [],<br>(<a href="mailto:r@127.0.0.1" target="_blank">r@127.0.0.1</a>)3> [{{const, Name}, '$2', '$3', '$4'}]<br>(<a href="mailto:r@127.0.0.1" target="_blank">r@127.0.0.1</a>)3> }]).<br>** exception error: bad argument<br> in function ets:select/2<br> called as ets:select(my_table,<br> [{{test,'$2','$3','$4','_','_'},<br> [],<br> [{{const,test},'$2','$3','$4'}]}])</font><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 10, 2020 at 5:05 PM Jacob <<a href="mailto:jacob01@gmx.net" target="_blank">jacob01@gmx.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
On 1/10/20 4:37 PM, Roberto Ostinelli wrote:<br>
> MatchBody = case is_tuple(Name) of<br>
> true -> {{{Name}, '$2', '$3', '$4'}};<br>
> _ -> {{Name, '$2', '$3', '$4'}}<br>
> end,<br>
> case ets:select(my_table, [{<br>
> {Name, '$2', '$3', '$4', '_', '_'},<br>
> [],<br>
> [MatchBody]<br>
> }])<br>
><br>
> I need to do this because to make it work for Name values of both test<br>
> and {test}.<br>
> Is there a better way?<br>
<br>
yes, by using a 'const' expression that will prevent variable substition<br>
and function (tuple) evaluation in the sub-expression (here Name):<br>
<br>
case ets:select(my_table, [{<br>
{Name, '$2', '$3', '$4', '_', '_'},<br>
[],<br>
[{{const, Name}, '$2', '$3', '$4'}]<br>
}])<br>
<br>
I assume there aren't nested tuples in Name, but just using {Name} like<br>
above would only prevent the outmost tuple from being interpreted as a<br>
"function" or variable. The 'const' expression is much safer here, since<br>
it just says: "include as is". See the ms_transform manpage for details.<br>
<br>
Jacob<br>
</blockquote></div>
</blockquote></div>