Assignment: I Do Not Think It Means What You Think It Means.

Let’s use the interactive Elixir shell, iex, to look at a really 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 one 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 = a match operator.

In this case, the left-hand ...

Get Programming Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.