[erlang-questions] Ets match on a record vs Dialyzer

Kostis Sagonas kostis@REDACTED
Fri Sep 18 21:15:32 CEST 2009


Zoltan Lajos Kis wrote:
> Hello,
> 
> I would like to match entries in an ets table based on some fields of 
> records, as in the example module below.
> When using the _='_' form for defining the "don't care" record fields, 
> Dialyzer emits the following (reasonable) warnings:
> 
> rec.erl:6: Function p/0 has no local return
> rec.erl:9: Record construction #rec{x::1,y::'_',z::'_'} violates the 
> declared type for #rec{}
> 
> With multiple functions and modules, the no local return causes an an 
> avalanche of further no local return's and never called's.
> 
> Of course I could redefine the field types as {x::integer()|'_', 
> y::integer()|'_', z::integer()|'_'} but I would prefer another match 
> syntax or Dialyzer directive if available. So what choices do I have?

 From the options you mention, the best is to use a more relaxed type 
declaration in the record fields of interest.

IMO, it was a design mistake to use a perfectly valid Erlang term 
(namely the atom '_') as a symbol with a different meaning in match 
specifications.

Kostis

> ----------------------
> 
> -module(rec).
> -export([p/0]).
> 
> -record(rec, {x::integer(), y::integer(), z::integer()}).
> 
> p() ->
>    ets:new(table, [named_table, {keypos, #rec.x}]),
>    ets:insert(table, [#rec{x=1,y=2,z=3}, #rec{x=4,y=5,z=6}]),
>    ets:match_object(table, #rec{x=1, _='_'}).
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org



More information about the erlang-questions mailing list