Another Way of Looking at the Equals Sign

Elixir’s pattern matching is similar to Erlang’s (the main difference being that Elixir allows a match to assign to a variable that was assigned in a prior match, whereas in Erlang a variable can be assigned only once).

Joe Armstrong, Erlang’s creator, compares the equals sign in Erlang to that used in algebra. When you write the equation x = a + 1, you are not assigning the value of a + 1 to x. Instead you’re simply asserting that the expressions x and a + 1 have the same value. If you know the value of x, you can work out the value of a, and vice versa.

His point is that you had to unlearn the algebraic meaning of = when you first came across assignment in imperative programming languages. Now’s the ...

Get Programming Elixir 1.3 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.