[erlang-questions] ets:match_delete

Anthony Ramine nox@REDACTED
Tue Jun 7 18:52:34 CEST 2011


Le 7 juin 2011 à 17:33, Roberto Ostinelli a écrit :

> dear list,
> 
> i'm trying to match delete elements from an ETS table which have one of the tuple elements greater than 2.
> 
> start() ->
>     ets:new(test, [named_table, set, protected]),
>     ets:insert(test, {a, 1, true, true}),
>     ets:insert(test, {b, 2, true, true}),
>     ets:insert(test, {c, 3, true, true}),
>     ets:insert(test, {d, 2, true, true}),
>     ets:insert(test, {e, 1, true, true}),
>     ets:match_delete(test, [{['_', '$1', '_', '_'], [{'>', '$1', 2}], []}]),
>     Result = ets:tab2list(test),
>     ets:delete(test),
>     Result.
> 
> this however does return the whole table.
> 
> any hints on what i'm doing wrong?
> 
> r.

[{{'_','$1','_','_'},[{'>','$1',2}],[]}] should work. You put a list instead of a tuple for the match argument.
By the way I didn't read the doc to figure it out, I just did ets:fun2ms(fun ({_,X,_,_}) when X > 2 -> X end),
which is pretty good for figuring out how to write matchspecs.

Regards,

--
Anthony Ramine
Dev:Extend
http://dev-extend.eu







More information about the erlang-questions mailing list