Re: maps inside records
Sergej Jurečko <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.bugs |
|---|---|
| Message-ID | <CAAbM2=YHUuZQwhnOMYZcLzVV5jLOwzfyv3k9b_=fTjuQds7DhQ@mail.gmail.com> |
Oh right. The #event is just in the print string, not the actual code. The code compiles and runs. Sergej On Mon, Feb 2, 2015 at 9:06 AM, Vlad Dumitrescu <[email protected]> wrote: > Hi Sergej, > > Is the code you pasted in the mails correct? You have references to both > #event and #ev -- maybe that's the cause? > > regards, > Vlad > > > On Mon, Feb 2, 2015 at 8:23 AM, Sergej Jurečko <[email protected]> > wrote: > >> >> >> On Mon, Feb 2, 2015 at 8:04 AM, Björn Gustavsson <[email protected]> >> wrote: >> >>> On Sun, Feb 1, 2015 at 9:47 AM, Sergej Jurecko <[email protected]> >>> wrote: >>> > Tested in 17.3 and 17.4 >>> > >>> > Incorrect behavior 1: >>> > >>> > -record(ev,{info}). >>> > test() -> >>> > test(#ev{info = #{type => dir, name => "My folder"}}). >>> > test(#ev{info = #{type := dir} = I} = E) -> >>> > io:format("E = ~p~n",[E]), >>> > io:format("E#event.info = ~p~n",[E#ev.info]), >>> > io:format("I = ~p~n",[I]). >>> > >>> > Calling test/0 will print: >>> > E = {ev,#{name => "My folder",type => dir}} >>> > E#event.info = #{type => dir} >>> > I = #{name => "My folder",type => dir} >>> > >>> > Why is E#event.info without name field? >>> > >>> >>> The behaviour is the expected. >>> >>> Records are compile-time construct that are translated >>> to tuples. So at run-time the record is a tuple and >>> will be printed as a tuple. >>> >> >> >> Yes but E#event.info value is not a record. It is a map which should >> contain #{type => dir, name => "My folder"}, yet when trying to extract >> that record we only get #{type => dir}. >> >> E#event.info should be the same as I, yet it is not. >> >> >> Sergej >> >> _______________________________________________ >> erlang-bugs mailing list >> [email protected] >> http://erlang.org/mailman/listinfo/erlang-bugs >> >> > _______________________________________________ erlang-bugs mailing list [email protected] http://erlang.org/mailman/listinfo/erlang-bugs