December 2019
Intermediate to advanced
248 pages
5h 34m
English
You’ve already seen one of our suggestions, to prefer strings for user-defined text and atoms for naming concepts in code. In this section, we’re going to dive a little deeper. Elixir’s strings have a slightly different set of characteristics from maps or lists, and you should know about those subtle differences. Let’s talk a little bit about these concepts.
Elixir has two different kinds of strings. The first is the charlist, and it’s just a list of characters, like this:
| | iex> [67, 65, 66] |
| | 'CAB' |
| | iex> ?C |
| | 67 |
Notice the single quotes. The representation of the charlist is simply a list of numbers, the ASCII codes for those characters. Use this datatype to work with the individual characters in a list, or when you are working ...
Read now
Unlock full access