English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
-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.
Number | Methods and Descriptions |
---|---|
1 | This method is used to determine whether an item is indeed an atom. |
2 | This method is used to convert atom values to lists. |
3 | This method is used to convert list items to atom. |
4 | This method is used to convert atom values to binary values. |
5 | This method is used to convert binary values to atom values. |