O'Reilly logo

Programming Elixir by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required