On Tue, Apr 10, 2018 at 1:32 AM Alex Dvoretskiy
wrote:
> Why there is no difference if the last comma exists?
Because the language specification allows to omit the last comma before the
closing '}':
LiteralValue = "{" [ ElementList [ "," ] ] "}" .
See: https://golang.org/ref/spec#Liter
My understanding is that this is a consequence of the semicolon insertion
rules Go uses. The Go parser actually uses semicolons internally, but they
are inserted before parsing so that the programmer doesn't have to.
Semicolons are added to the end of a line if the line ends with:
- an identifier
Hello Golangnuts,
Why there is no difference if the last comma exists?
{'A', 'B', 'C', 'E'}
or
{'A', 'B', 'C', 'E',}
both are valid.
Sometimes it causes little troubles. For example, the second snippet
wouldn't compile, because of different formatting. But these two snippets
are identical