May 2018
Intermediate to advanced
412 pages
9h 3m
English
Let’s use the interactive Elixir shell, IEx, to look at a simple piece of code. (Remember, you start IEx at the command prompt using the iex command. You enter Elixir code at its iex> prompt, and it displays the resulting values.)
| | iex> a = 1 |
| | 1 |
| | iex> a + 3 |
| | 4 |
Most programmers would look at this code and say, “OK, we assign 1 to a variable a, then on the next line we add 3 to a, giving us 4.”
But when it comes to Elixir, they’d be wrong. In Elixir, the equals sign is not an assignment. Instead it’s like an assertion. It succeeds if Elixir can find a way of making the left-hand side equal the right-hand side. Elixir calls the = symbol the match operator.
In this case, the left-hand ...
Read now
Unlock full access