liveBook · Manning

Atom

As explained in Elixir in Action, Third Edition

An atom is an Elixir named constant whose text is stored in the runtime atom table and whose value is a reference to that text.

An atom is an Elixir named constant. Its text is stored in the runtime atom table, while the value holds a reference to that text, keeping comparisons fast, memory use low, and code readable. section 2.4.2

Atoms support several language-level roles:

  • Write ordinary constants with a colon, such as :an_atom, or quote names containing spaces. section 2.4.2
  • Use uppercase names as aliases; the compiler transforms AnAtom into the atom :"Elixir.AnAtom". section 2.4.2
  • Represent booleans with true and false atoms, use nil as the null value, and use module names as atoms at runtime. section 2.4.2 section 2.7.1
iex(1)> AnAtom == :"Elixir.AnAtom"
true

Verify that an uppercase alias and its fully qualified atom are identical. section 2.4.2

iex(1)> true and false
false

iex(2)> false or true
true

iex(3)> not false
true

iex(4)> not :an_atom_other_than_true_or_false
** (ArgumentError) argument error

Observe boolean operators accepting true and false while rejecting unrelated atoms with not. section 2.4.2

How Elixir in Action, Third Edition covers it

How deep it goes
Explains syntax, atom-table representation, aliases, boolean behavior, and module-name resolution at runtime.
Examples
Demonstrates quoted atoms, alias equality, boolean operators, nil, module definitions, and dynamic calls.
What you can do after
Evaluate atom identity, choose atoms for named constants, and recognize their roles in modules and boolean expressions.
How it connects
Connects atoms with aliases, booleans, nil, modules, functions, and dynamic function calls.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.