Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  Ets match on a record vs Dialyzer

Guest
Posted: Fri Sep 18, 2009 7:01 pm Reply with quote
Guest
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?

Best Regards,
Zoltan.

----------------------

-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

Post received from mailinglist
warezio
Posted: Fri Sep 18, 2009 7:10 pm Reply with quote
User Joined: 05 May 2007 Posts: 107 Location: Yahoo
On Fri, 18 Sep 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?

I've had this problem constantly. I've moved away from relaxing the type
specification in the record, and towards using setelement/3 to hide from
the dialyzer. It helps that when using mnesia you get
mnesia:table_info (Table, wild_pattern) to initialize the record.

Cheers,

-- p

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
View user's profile Send private message Yahoo Messenger
Guest
Posted: Fri Sep 18, 2009 7:17 pm Reply with quote
Guest
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


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
Guest
Posted: Fri Sep 18, 2009 7:26 pm Reply with quote
Guest
Kostis Sagonas wrote:
> 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
I have to agree. For some reason I believed '_' and '$1' are merely
syntactic sugar, and they are magically transformed into some sort of
match specifications. I had some fun trying to figure out how to make
the compiler accept expressions like #rec{x=1, _='_'} = '$1' until I
realized these really are just atoms Smile
>
>> ----------------------
>>
>> -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
>


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
wuji
Posted: Tue Aug 28, 2012 7:39 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
lecture Thursday, Oberle crossed one of two fences separating him him cheap designer *beep* him from the animals into a "no go zone," Cussons
Oberle did not have clearance to be standing in the the cheap Ralph Lauren the area past the public fence. Oberle stepped on a
peeceived by the chimps as their terrority when he neared neared cheap replica *beep* neared an electrified fence. Two male chimpanzees named Nikki and
reached underneath pulled him halfway under the fence by his his cheap polo shirts his foot. Oberle fought to not be pulled into the
At this point, the sanctuary instituted its lockdown procedure, Cussons Cussons [h3]cheap polo shirts[/h3] Cussons said. The institute believes the chimpanzees were able to
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum