[erlang-questions] The compiler "eats" structures which are not separated by commas
Vlad Dumitrescu
vladdu55@REDACTED
Fri Apr 20 14:11:49 CEST 2012
On Fri, Apr 20, 2012 at 13:54, Serge Polkovnikov
<serge.polkovnikov@REDACTED> wrote:
> 20 апреля 2012 г. 14:34 пользователь Vlad Dumitrescu <vladdu55@REDACTED>
> написал:
>> 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?
No, because this is a perfectly reasonable language construct. It's
the same as in any other language if you compare "foo(1, -2)" and
"foo(1 -2)".
One could detect such repeated assignment to the same field, but I
don't think it's easy to make it work in the general case (some use
cases might be valid).
regards,
Vlad
More information about the erlang-questions
mailing list