An atom is a literal, a constant with name. An atom is to be enclosed in single quotes (') if it does not begin with a lower-case letter or if it contains other characters than alphanumeric characters, underscore (_), or @.
The following program is an example of how atoms can be used in Erlang. This program declares 3 atoms, atom1, atom_1 and ‘atom 1’ respectively. So you can see the different ways an atom can be declared.
-module(helloworld). -export([start/0]). start() -> io:fwrite(atom1), io:fwrite("~n"), io:fwrite(atom_1), io:fwrite("~n"), io:fwrite('atom 1'), io:fwrite("~n").
The output of the above program would be follows −
atom1 atom_1 atom 1
Let’s see some of the methods available in Erlang to work with atoms.
|Sr.No.||Methods and Description|
This method is used to determine if a term is indeed an atom.
This method is used to convert an atom to a list.
This method is used to convert a list item to an atom.
This method is used to convert an atom to a binary value.
This method is used to convert a binary value to an atom value.