English 中文(简体)
Erlang - Atoms
  • 时间:2024-10-18

Erlang - Atoms


Previous Page Next Page  

An atom is a pteral, 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.

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 would be follows −

Output

atom1
atom_1
atom 1

Let’s see some of the methods available in Erlang to work with atoms.

Sr.No. Methods and Description
1

is_atom

This method is used to determine if a term is indeed an atom.

2

atom_to_pst

This method is used to convert an atom to a pst.

3

pst_to_atom

This method is used to convert a pst item to an atom.

4

atom_to_binary

This method is used to convert an atom to a binary value.

5

binary_to_atom

This method is used to convert a binary value to an atom value.

Advertisements