[erlang-questions] The compiler "eats" structures which are not separated by commas

Håkan Nilsson <>
Fri Apr 20 16:58:30 CEST 2012


That's why it's preferable to have the convention to put the comma in the
beginning om the line, like this:

[ #haha{v=1}
, #haha{v=2}
, #haha{v=3}
].

It looks kinda funky at first sight, but once you get used to it then it
will make your life easier.

2012/4/20 JD Bothma <>

> Sadly erlang doesn't allow a trailing comma in the last element like
>
> [
>  #haha{v=1},
>  #haha{v=2},
>  #haha{v=3},
> ].
>
> otherwise, always trailing with a comma is a common best practise,
> e.g. in PHP arrays. When it becomes habit it's hardly a problem.
>
> Since this can silently cause bugs, the warning suggested in
> http://erlang.org/pipermail/erlang-bugs/2011-July/002528.html sounds
> like a good thing to push for, unless there's a better solution?
>
> JD
>
> On 20 April 2012 13:54, Serge Polkovnikov <>
> wrote:
> >
> >
> > 20 апреля 2012 г. 14:34 пользователь Vlad Dumitrescu <
> >
> > написал:
> >
> >> Hi Serge,
> >>
> >> On Fri, Apr 20, 2012 at 13:27, Serge Polkovnikov
> >> <> wrote:
> >> > The compiler "eats" structures which are not separated by commas.
> >> > start() ->
> >> >     [
> >> >      #haha{v=1}   %% No comma here
> >> >      #haha{v=2}   %% No comma here
> >> >      #haha{v=3}
> >> >     ].
> >>
> >> No, the code is equivalent to ((#haha{v=1})#haha{v=2})#haha{v=3}.
> >
> >
> > Is there any simple way to protect such lists against the behaviour?
> >>
> >>
> >> Try the following to understand:
> >>
> >> -record(haha,  { a,b,c } ).
> >>  start() ->
> >>      [
> >>       #haha{a=1}   %% No comma here
> >>       #haha{b=2}   %% No comma here
> >>       #haha{c=3}
> >>      ].
> >>
> >> regards,
> >> Vlad
> >
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Håkan Nilsson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120420/646847c6/attachment.html>


More information about the erlang-questions mailing list