Understanding the behavior of erlang ETS match specs

Viewed 181

I am trying to build a match spec on a DETS table and I've ran into something that puzzles me.

The Structure of the table entries look as follows:

{'RECORD_KEY','BODY_TUPLE'}

the 'RECORD_KEY' term looks like this {shell,T1,T2,T3,T4,T5,T6}

If I match spec on this:

{{' _','_','$1','_','_','_'},'$2'} 

ie: dets:match(Ref, {{'_','_','$1','_','_','_'},'$2'} )

I get all entries in the table. However, now I try to add some other terms to the match spec so I can start adding guards like this:

  Terms = {{' _','_','$1','_','_','_'},'$2'},
  Gaurds = [],
  Returns = ['$1'],
  Pattern = [{Terms,Gaurds,Returns}],
Matches = dets:match(Ref, Terms),

which returns NO entries, even if I replace the '$1' with '$_'.

What am I doing wrong here?

1 Answers

Okay I feel kind of stupid, I've actually used ETS tables quite a bit last year and I forgot that ets:match and ets:select are two different functions. I should have used SELECT.

Related