Strictly speaking the match happens on the left side of =
- the right side is strictly off limits and remains strictly whatever value the expression evaluates to.
You have to make an accommodation for the fact that programming languages have an underlying grammar - for example this is an Erlang grammar (as expressed for yecc).
In a sense you are demanding that each letter in the alphabet has its own unique meaning, because you don’t want to be bothered with recognizing words - and it is not like you verbally spell out each letter for every word that you enunciate.
In reference to beginners I think it is extremely important for them to realize that in fact there is a difference. They need to train themselves to recognize the patterns that appear in the language’s grammar in order to identify the semantics of the expression - and =
isn’t a pattern - ultimately it’s just a glyph in the textual representation of the expression.
Also beginners gravitate towards a “register-model” for the mental model of variables - i.e. name
simply identifies a location capable of containing the value "José"
- so when you “assign” "Chris"
, they imagine the "José"
value being replaced/destroyed by the "Chris"
value in that location. But that is not what is going on in
name = "José"
name = "Chris"
Both "José"
and "Chris"
are immutable values (data) and name
is simply an identifier. The first match expression succeeds leaving name
bound to the "José"
data. The second match expression succeeds by binding name
to the "Chris"
data. Oversimplification lets beginners adopt a mental model that becomes an obstacle to more advanced learning later.