[erlang-bugs] parser/preprocessor bug

Raimo Niskanen <>
Mon Nov 21 14:02:01 CET 2011


On Fri, Nov 18, 2011 at 09:51:08PM +0000, Robert Virding wrote:
> Originally the parentheses were mandatory but then the need for them around an record expression was removed to "improve" the syntax. Only in some cases though. Sorry for griping but I think it was a bad change. Other people have had exactly the same errors.

Yes. It has now become a pitfall worth repeating.

The intention was to improve (simplify) the syntax for nested records e.g:
  Y = X#outer_record.a#inner_record.b
was syntactically invalid and had to be written:
  Y = (X#outer_record.a)#inner_record.b

/ Raimo



> 
> Robert
> 
> ----- Original Message -----
> > On Fri, Nov 18, 2011 at 03:46:16PM +0100, Joe Armstrong wrote:
> > > On Fri, Nov 18, 2011 at 2:16 PM, Vlad Dumitrescu
> > > <> wrote:
> > > 
> > > > Hi,
> > > >
> > > > On Fri, Nov 18, 2011 at 14:11, Joe Armstrong <>
> > > > 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
> > > 
> > > http://erlang.org/mailman/listinfo/erlang-bugs
> > 
> > 
> > --
> > 
> > / Raimo Niskanen, Erlang/OTP, Ericsson AB
> > _______________________________________________
> > erlang-bugs mailing list
> > 
> > http://erlang.org/mailman/listinfo/erlang-bugs
> > 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-bugs mailing list