October 2014
Intermediate to advanced
280 pages
7h 20m
English
When we write modules in Elixir, they have names such as String or PhotoAlbum. We call functions in them using calls such as String.length("abc").
What’s happening here is subtle. Internally, module names are just atoms. When you write a name starting with an uppercase letter, such as IO, Elixir converts it internally into an atom called Elixir.IO.
| | iex> is_atom IO |
| | true |
| | iex> to_string IO |
| | "Elixir.IO" |
| | iex> :"Elixir.IO" === IO |
| | true |
So a call to a function in a module is really an atom followed by a dot followed by the function name. And, indeed, we can call functions like this:
| | iex> IO.puts 123 |
| | 123 |
| | :ok |
| | iex> :"Elixir.IO".puts 123 |
| | 123 |
| | :ok |
Read now
Unlock full access