Elixir supports a special syntax for defining such lists: [key: value]. Underneath it maps to the same list of tuples as above.
but also
Keyword lists are important because they have three special characteristics:
Keys must be atoms.
Keys are ordered, as specified by the developer.
Keys can be given more than once.
So if both syntaxes are the same the why the second code doesn’t work? Or is the first code just a list of tuples (different than keyword list) because the first key in each tuple is not an atom?
Testing this in IEX it looks like atoms can’t start with a digit but according to Programming Elixir atoms can be written…
…using a leading colon (:), followed by an atom word or an Elixir operator. An atom word is a sequence of letters, digits, underscores, and @ signs). It may end with an exclamation point or a question mark.
:120 is not valid elixir. The erlang atom '120' has to et written as :"120" in elixir. But in a sense you are right, one can’t use non-atoms as keys for that syntactic sugar but one has to use atoms as described in the docs.
It used when referring functions or map keys that have ? or ! on the end, so :valid? or :fetch!.
For example, in Ecto.Changesets, valid? is a field, not a function like in ActiveRecord::Base You can match against it to match valid changesets only as follows: