Atoms

Contents
What atoms are
Atom rules
Compare atoms
Atom tools

What atoms are

An atom is a constant whose name is its value. Atoms carry no data of their own; they mark states, results, and keys.

The two most famous atoms are true and false, and the third is nil, the empty list. You will meet all three in lesson 9.

ok.

ok

2> error.

error

Atom rules

An atom starts with a lowercase letter and continues with letters, digits, underscores, and the at sign. Anything richer needs single quotes, and the quotes become part of the atom.

Atoms are not garbage collected in the old sense: the atom table is global and bounded, so never build them from user input in a loop.

max_value.

max_value

2> 'Tuesday morning'.

'Tuesday morning'

Compare atoms

The double equals compares values loosely, and the triple equals compares types strictly. Atoms never equal numbers, even when they look alike.

Use the strict form by default: it keeps 1 and 1.0 apart and makes every test predictable.

ok =:= ok.

true

2> ok == ok.

true

3> 1 == 1.0.

true

Atom tools

The atom module converts between atoms and strings. list_to_atom builds an atom at runtime, which is the one place to be careful with the atom table.

atom_to_list(ok).

"ok"

2> list_to_atom("ready").

ready

Next: Strings and binaries

Article author: Arthur Isaev

Related articles
Erlang
Erlang course: zero to hero in 50 lessons
What is Erlang and where it runs
Install Erlang and check the version
erl: the interactive shell
Your first Erlang script
Variables and single assignment
Numbers
Atoms
Strings and binaries
Truthiness: only false and nil
Conditions: case and if
Recursion replaces loops
Lists
Tuples
Maps
Functions and clauses
Pattern matching
Guards
Records
Exceptions: try and catch
Modules, exports and imports
Funs: anonymous functions
Higher-order functions
Keyword lists
Erlang idioms and clean code
Rebar3 builds
Testing with EUnit
Debugging
Encodings and Unicode
Time and date
JSON and term formats
Processes and message passing
Spawn and links
Monitors and exits
GenServer
Supervisors
OTP applications
Files and IO
Sockets
HTTP clients
io:format and output
Let it crash: error handling
ETS tables
Timers and timeouts
Code loading
Distributed Erlang
Capstone: todo CLI
Capstone: TCP server
Performance
Modern Erlang tour
Hero roadmap: the whole course on one page
Install Erlang on Windows 11
Install Erlang on Ubuntu
Install Erlang on Rocky Linux
Install Erlang on macOS
Install Erlang on FreeBSD
Erlang in Docker
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: