Currently trying to understand the "^" operator in Elixir. From the website:
The pin operator ^ can be used when there is no interest in rebinding a variable but rather in matching against its value prior to the match:
Source - http://elixir-lang.org/getting_started/4.html
With this in mind, you can attach a new value to a symbol like so:
iex> x = 1 # Outputs "1"
iex> x = 2 # Outputs "2"
I can also do:
iex> x = x + 1 # Outputs "3"!
So my first question is; Are Elixir variables mutable? It sure looks like if that's the case... Shouldn't that be possible in a functional programming language?
So now we come to the "^" operator...
iex> x = 1 # Outputs "1"
iex> x = 2 # Outputs "2"
iex> x = 1 # Outputs "1"
iex> ^x = 2 # "MatchError"
iex> ^x = 1 # Outputs "1"
I think the effect of "^" is to lock "x" to the last value binded to it. Is that all there is to it? Why not just ensure that all 'matches'/assignments are immutable like Erlang itself?
I was just getting used to that...