[erlang-questions] The compiler "eats" structures which are not separated by commas
Max Bourinov
bourinov@REDACTED
Sat Apr 21 09:38:16 CEST 2012
+1. I also use this technique.
Sent from my iPhone
On 20.04.2012, at 18:59, "Håkan Nilsson" <hakan.nilsson@REDACTED> wrote:
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 <jbothma@REDACTED>
> 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 <serge.polkovnikov@REDACTED>
> wrote:
> >
> >
> > 20 апреля 2012 г. 14:34 пользователь Vlad Dumitrescu <vladdu55@REDACTED
> >
> > написал:
> >
> >> Hi Serge,
> >>
> >> On Fri, Apr 20, 2012 at 13:27, Serge Polkovnikov
> >> <serge.polkovnikov@REDACTED> 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
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
--
Håkan Nilsson
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120421/7bc44697/attachment.htm>
More information about the erlang-questions
mailing list