How do you refer to the Match Operator when reading code?

___ is bound to ___

5 Likes

In my mind, it reads something like this:

“I am making the assertion that the variable name is bound to the value "José". If the variable name is not bound to any value, then name will get bound the value "José" and my assertion will be true. If name is bound to any value other than "José", then my assertion will be false.”

Actually, it is not true. name will be re-bound.

name = "any other value"
name = "José"

Oh, yes! You’re right. My brain relapsed to “Erlang-mode” when writing that :blush:

Which is funny, because I just started a thread about this exact topic:

2 Likes

I say name is matched and assigned to “José”. Because if it’s not an existing variable, it’s assigned.

It makes more sense to me when pattern matching.

{:ok, name} = {:ok, "Jose"}