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

Tomasz Maciejewski <>
Fri Apr 20 13:34:46 CEST 2012


W dniu 20 kwietnia 2012 13:27 użytkownik Serge Polkovnikov
<> napisał:
> start() ->
>     [
>      #haha{v=1}   %% No comma here
>      #haha{v=2}   %% No comma here
>      #haha{v=3}
>     ].

This is not a bug. The "Foo#bar" syntax tells the compiler to treat
Foo as a bar instance. But this doesn't forbid Foo being also
"Something#bar". So your code tells the compiler to get #haha{v=1},
substitute v with 2, and then subsitute v with 3. That's why you end
up with [{haha, 3}].

If you had a record with fields v and w, then:

[
 #haha{v=1}
 #haha{w=3}
]

would return a list [{haha,1,3}]

-- 
Tomasz Maciejewski



More information about the erlang-questions mailing list