Module Names: Elixir, Erlang, and Atoms

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 of the same name with Elixir. prepended. So IO becomes Elixir.IO and Dog becomes Elixir.Dog.

 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

and even

 iex>​ my_io = IO
 IO
 iex>​ my_io.puts 123
 123
 :ok