English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Erlang Atoms (Atom)

An atom is a literal, a named constant. If an atom does not start with a lowercase letter, or contains alphanumeric characters, underscores (_) or @, it should be enclosed in single quotes (').

This program is an example of how to use atoms in Erlang. The program declares3atoms, respectively atom1,atom_1and 'atom 1Thus, you can see the different methods for declaring atoms.

Online Example

-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 is as follows:

atom1
atom_1
atom 1

Let's take a look at some methods available in Erlang for atoms.

NumberMethods and Descriptions
1

is_atom

This method is used to determine whether an item is indeed an atom.

2

atom_to_list

This method is used to convert atom values to lists.

3

list_to_atom

This method is used to convert list items to atom.

4

atom_to_binary

This method is used to convert atom values to binary values.

5

binary_to_atom

This method is used to convert binary values to atom values.