[erlang-bugs] parser/preprocessor bug

Raimo Niskanen raimo+erlang-bugs@REDACTED
Fri Nov 18 17:04:13 CET 2011


On Fri, Nov 18, 2011 at 03:46:16PM +0100, Joe Armstrong wrote:
> On Fri, Nov 18, 2011 at 2:16 PM, Vlad Dumitrescu <vladdu55@REDACTED> wrote:
> 
> > Hi,
> >
> > On Fri, Nov 18, 2011 at 14:11, Joe Armstrong <erlang@REDACTED> wrote:
> > > -module(bug).
> > > -compile(export_all).
> > > -record(bug,{a}).
> > > test() ->
> > >     [#bug{a=1} #bug{a=2}].
> >
> > It's not a bug, it's the same as
> >
> > test() ->
> >    B = #bug{a=1},
> >     [B#bug{a=2}].
> >
> >
> Ouch - oh dear you're right.
> 
> When I wrote this I thought #bug{a=1} is syntactic sugar for {bug,1}
> therefore [#bug{a=1} #bug{a=2}] is the same as [{bug1,} {bug,2}] which is
> an invalid list.

I have not tried but you can think of it like that:
  [#bug{a=1} #bug{a=2}]
is
  [{bug,1} #bug{a=2}] %% uncertain if valid
is
  [setelement(2, {bug,1}, 2)]

since R#bug{a=A} is syntactical sugar for (kind of)
  if is_record(R, bug) -> setelement(2, R, A) end
in the context of your record definition.

> 
> /J
> 
> 
> 
> 
> 
> > regards,
> > Vlad
> >

> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs


-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-bugs mailing list