unix1
January 29, 2022, 11:29pm
1
This has tripped me up a couple of times I missed a comma in a long list of maps
1> #{a => b}#{c => d}.
#{a => b,c => d}
I would have expected this to be a syntax error, but it compiles and then troubleshooting takes a lot longer. Is there any good reason for it?
3 Likes
lpil
January 29, 2022, 11:57pm
2
The reason is that any expression is permitted on the left hand side of the map update syntax. It would be more work and less consistent for the compiler to allow any expression except for a map literal.
It can be fun to test out what odd things like this you can get a language parser to accept, they’re typically a lot more lenient than you might expect.
7 Likes
Taure
January 29, 2022, 11:57pm
3
I guess it is a valid map you could also do.
Map = #{a => b}.
Map#{c => d}.
But yes it have bitten me too.
4 Likes
For reference, I once wrote an article about that…
7 Likes
Something good to add to a linter though?
5 Likes
opened 10:27PM - 14 Apr 17 UTC
enhancement
The idea behind this rule comes from [this email](http://erlang.org/pipermail/er… lang-questions/2017-April/092112.html) by @kvakvs.
Basically, the goal is to emit a warning if someone _forgets a comma_ and writes something like:
```erlang
[#{a => 1}
#{b => 2}]
```
It will also warn on things like ``#{a =>1}#{b => 2}``, but I think it's worth it since that expression is easily rewritable as ``#{a => 1, b => 2}``.
and now that we’re at it…
opened 01:04PM - 12 Jul 17 UTC
enhancement
rule
hacktoberfest
Having:
`#{key := A, x := X, y := Y, key := B}` = ZZZ,
on the left of a patter… n is not an error but can be very confusing. It could be a warning.
Having it on the right side of a pattern, or in a free-standing expression — is not an error but most likely is a sign of a typo, or a copy-paste error.
`ZZZ = #{key => A, x => xxx, y => yyy, key => B}`
…and we’re always happy to review and merge PRs for new rules
2 Likes
Ahh, that’s an old still open issue…
1 Like