You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's mentioned as part of the definition of maps and keyword list, when within %{…} and […] (here). Given here it's taken as a keyword list, but without explicit square brackets, the section on optional square brackets is also relevant (here).
Elixir also supports a syntax where if the last argument of a call is a keyword list then the square brackets can be skipped.
Calls are earlier in the document defined to be non-qualified calls (fun(…)) or qualified calls (Mod.fun(…)). Both include
…, must start with characters and then follow the same rules as variables, which are optionally followed by parentheses, and then arguments.
Tuple creation doesn't fit that picture painted by those parts of the syntax reference. I would've expected that square brackets would be required for a keyword list being the last element of a tuple.
@michalmuskala showed on slack that the following is also valid syntax, but in that case it doesn't evaluate to a valid value:
I can't say what's wrong here, documentation or implementation, but coming from the documentation the current behaviours looks like a bug. If that's not a bug then I think the documentation needs adjustment.
The text was updated successfully, but these errors were encountered:
Elixir and Erlang/OTP versions
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Interactive Elixir (1.17.0) - press Ctrl+C to exit (type h() ENTER for help)
Operating system
Mac OS
Current behavior
{1, a: :b}
is valid syntax and evalutes to{1, [a: :b]}
.This came up recently on https://elixirforum.com/t/keyword-inside-tuple-shorthand-syntax-a-1-b-2/63960, but also had someone ask on the slack beginner channel about it today.
Expected behavior
On https://hexdocs.pm/elixir/syntax-reference.html there are two sections related to
a: :b
key/value pairs.It's mentioned as part of the definition of maps and keyword list, when within
%{…}
and[…]
(here). Given here it's taken as a keyword list, but without explicit square brackets, the section on optional square brackets is also relevant (here).Calls are earlier in the document defined to be non-qualified calls (
fun(…)
) or qualified calls (Mod.fun(…)
). Both includeTuple creation doesn't fit that picture painted by those parts of the syntax reference. I would've expected that square brackets would be required for a keyword list being the last element of a tuple.
@michalmuskala showed on slack that the following is also valid syntax, but in that case it doesn't evaluate to a valid value:
I can't say what's wrong here, documentation or implementation, but coming from the documentation the current behaviours looks like a bug. If that's not a bug then I think the documentation needs adjustment.
The text was updated successfully, but these errors were encountered: