[erlang-questions] Comparing tuple records in MatchSpec

Anthony Ramine <>
Sat Apr 27 16:14:56 CEST 2013

Hello Maruthavanan,

You need to escape the tuples StartTime and EndTime as tuples have a special meaning in match specifications.

The documentation states[1]:

> Literals in theMatchCondition/MatchBody can either be written as is, which works for all literals except tuples, or by using the special form {const, T}, where T is any Erlang term. For tuple literals in the match_spec, one can also use double tuple parentheses, i.e., construct them as a tuple of arity one containing a single tuple, which is the one to be constructed. The "double tuple parenthesis" syntax is useful to construct tuples from already bound variables, like in {{'$1', [a,b,'$2']}}.

So do either {StartTime} or {const,StartTime}.

But as Anders said, using ets:fun2ms/1 would be more readable.


[1] http://www.erlang.org/doc/apps/erts/match_spec.html

Anthony Ramine

Le 26 avr. 2013 à 21:58, Maruthavanan Subbarayan a écrit :

> Hi,
> i have mnesia table which stores date in tuple format {Y,M,D}, 
> To fetch data that falls on given date frames I tried to use this record
> MatchSpec = [{#appointment{id='$1', starttime = '$2', endtime = '$3',  _='_'},
>                         [{'orelse',{'>=','$2',StartTime},{'orelse',{'=<','$3',EndTime}}}],
>                         ['*']}] 
> where Startime and Endtime are records. This throws and bad arg during transaction.
> But when I change the Startime and End time as integer or list it executes without any problem.
> Is this the normal behaviour, or am I missing out anything, Any work around to achieve this?
> Thanks,
> Marutha
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list