But there is no such thing as “binding assignment operator” in Elixir. There is only pattern matching (with potential rebinding). So I do not really get how these operators would differ.
Pattern-matching IS binding assignments, there’s no difference. An example:
{:ok, something} = MyFunc.call(params)
response = MyFunc.call(params) # Returns same, now `response` is bound as {:ok, something}
If you are a “language promoter” with the goal of teaching Elixir, you should probably spend some more time writing it, so you’re comfortable with how the language works.
I asked this question because my team and I come from non-functional languages.
I am learning and really enjoying the practicality and ergonomics of Elixir and the capabilities of Erlang/OTP.
Without a doubt, I must and need to improve my understanding of the language further.
I thought that differentiating ‘Pattern matching’ from ‘binding assignments/rebinding’ would be simpler for understanding the Functional Paradigm, which is the heart of functional languages.
It was not my intention to modify the language into something meaningless.
At first I also had a hard time accepting that there was no difference between pattern matching and assignment, especially when you’re told = is not “assign” but “match” and then get an example of foo = "bar" # "bar"
The guides have been improved a bit since I initially read them by immediately showing the “inverse” expression:
iex> x = 1
1
iex> 1 = x
1
1 = x is an brow-raiser for newbies but I think they must get some idea that it’s a special case to put a variable on the right hand side or something? I’m only guessing, but I find that showing them this last example really tends to drive it home that = really indeed not an assignment operator:
iex> 1 = 1
1
I always explain it as assignment being a side effect of matching. I know that’s sorta overloading a term, but it seems to help in the beginning, lol.
Think of it this way: ‘=’ is binding assignment within a pattern matching. There is no pattern matching without binding operator because it would be a useless thing to do, other than being an assertion. If you must, you can wrap a scope around it to avoid pollution:
iex(13)> x = 1
1
iex(14)> if true, do: x = 2
warning: variable "x" is unused (there is a variable with the same name in the context, use the pin operator (^) to match on it or prefix this variable with underscore if it is not meant to be used)
iex:14
2
iex(15)> x
1