ets question

Serge Aleynikov serge@REDACTED
Tue May 10 16:06:38 CEST 2005


Chandrashekhar,

Thank you.  I just re-read the definition of ets:select_delete/2, and 
indeed, it said:

"If the match_spec returns the atom true for an object, that object is 
removed from the table. For any other result from the match_spec the 
object is retained."

So, as you correctly pointed out the proper use of the transform 
therefore should be:

ets:select_delete(a, ets:fun2ms(fun({1,2}) -> true end)).

Serge

Chandrashekhar Mullaparthi wrote:
> Serge,
> 
> The MatchSpec should be slightly different for select_delete to work. 
> Instead of
> 
> [{{1,2},[],['$_']}]
> 
> which is the result of the ets:fun2ms/1 call you have, the MatchSpec 
> should look like this:
> 
> [{{1,2},[],[true]}]
> 
> 12> ets:new(a, [named_table]).
> a
> 13> true = ets:insert(a, {1,2}).
> true
> 14> ets:select_delete(a, [{{1,2},[],[true]}]).
> 1
> 
> cheers
> Chandru
> 
> On 9 May 2005, at 21:49, Serge Aleynikov wrote:
> 
>> Hi All,
>>
>> I have the following question about ets:select_delete().  What do you 
>> think this function t() should return?
>>
>> -include_lib("stdlib/include/ms_transform.hrl").
>>
>> t() ->
>>     a = ets:new(a, [named_table]),
>>     true = ets:insert(a, {1,2}),
>>     M = ets:fun2ms(fun({1,2}) -> object() end),
>>     [{1,2}] = ets:select(a, M),
>>     ets:select_delete(a, M).
>>
>> I would expect it to return 1, yet it returns 0.  What am I missing?
>>
>> Thanks.
>>
>> Serge



More information about the erlang-questions mailing list