3 ms·
Elixir has borrowed the pattern matching approach from Erlang, but allows rebinds which makes code refactoring easier. iex(1)> x = 1 1 iex(2)> x = 2 2 iex(3)>
by aprao 9y ago
Elixir has borrowed the pattern matching approach from Erlang, but allows rebinds which makes code refactoring easier.
iex(1)> x = 1
1
iex(2)> x = 2
2
iex(3)> ^x = 3
(MatchError) no match of right hand side value: 3
Notice the pin operator (^) to achieve the same effect.
- dxhdr 9y agoI've used Erlang but not Elixir. Having an additional optional "pin" operator sounds like a bad idea, just piling on complexity. You can't mess up with the Erlang syntax.
- glorioustao 9y agoThe creator of elixir had a blog on this: http://blog.plataformatec.com.br/2016/01/comparing-elixir-and-erlang-variables/ http://blog.plataformatec.com.br/2016/01/comparing-elixir-an...
- gcb0 9y agoonly the case argument there is any good. when it get to numbered vars, you know they are grasping for anything