How Many Maps?

Quick question: how many maps do we have in the following list?

[#{a => 1},

#{b => 2}

#{c => 3}].

1

2

3

That doesn’t even compile!

People following the erlang-questions mailing list might know already, but the correct answer is not 3, nor a compile error. It’s 2.

Why not 3?

Well, there is a missing comma in the second row.

But why does it compile, then?

Because what’s written there is a perfectly valid expression, of course. And it matches the syntax used for records, as it’s pointed out in this thread:

-module(sample).



-record (a, {field1, field2}).



-export([bug/0]).



bug() ->

[

#a{field1 = 1, field2 = "foof"} %% COMMA IS MISSING

#a{field1 = 2},

#a{field1 = 3}

].

that function on the shell returns a list with 2 elements, as expected…