I have heard that specifying records through tuples in the code is a bad practice: I should always use record fields (#record_name{record_field = something}
) instead of plain tuples {record_name, value1, value2, something}
.
But how do I match the record against an ETS table? If I have a table with records, I can only match with the following:
ets:match(Table, {$1,$2,$3,something}
It is obvious that once I add some new fields to the record definition this pattern match will stop working.
Instead, I would like to use something like this:
ets:match(Table, #record_name{record_field=something})
Unfortunately, it returns an empty list.
#record_name{f1='$1',f2='$2',record_field=something}
you gave the example:#record_name{record_field=something,_='_'}.
That makes it seem like writing_='_'
once will match all the other fields--but in my attempts you have to write_='_'
for each additional field. That means if you change your record definition to have more or fewer fields, then you also have to change your match spec--which obviously is not ideal. The one nice thing is: you don't have to specify the field you are matching, e.g.record_field=something
, in the correct position in the tuple... – Philippic