May 2018
Intermediate to advanced
412 pages
9h 3m
English
Single-quoted strings are represented as a list of integer values, each value corresponding to a codepoint in the string. For this reason, we refer to them as character lists (or char lists).
| | iex> str = 'wombat' |
| | 'wombat' |
| | iex> is_list str |
| | true |
| | iex> length str |
| | 6 |
| | iex> Enum.reverse str |
| | 'tabmow' |
This is confusing: IEx says it is a list, but it shows the value as a string. That’s because IEx prints a list of integers as a string if it believes each number in the list is a printable character. You can try this for yourself:
| | iex> [ 67, 65, 84 ] |
| | 'CAT' |
You can look at the internal representation in a number of ways:
| | iex> str = 'wombat' |
| | 'wombat' |
| | iex> :io.format "~w~n" |
Read now
Unlock full access