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

JD Bothma jbothma@REDACTED
Fri Apr 20 14:11:12 CEST 2012


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
>



More information about the erlang-questions mailing list