Atoms, Pattern Matching, and Erlang Access
We’re going to start with atoms, a data type that might be confusing to Java, C, or C# developers. If you’re a Ruby developer, atoms are like symbols. If you come from Erlang, the data type is the atom.
Exploring a Type in IEx
Open up an IEx console and we’ll get right to work. So, what’s an atom?
| iex> :atom |
| :atom |
Atoms are names for concepts. Some good examples are :north, :string, and :yellow. Preface an atom with a colon, followed by a word starting with an alphabetic character.
You’re not limited to atoms with simple characters. By placing double quotes around the text to the right of the colon, you can make more complex atoms like :"blue-green" that would otherwise be invalid. In Elixir, we ...
Get Programmer Passport: 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.