Erlang Central

Atom

Revision as of 08:37, 2 September 2006 by Rvg (Talk | contribs)

Most languages, including C, C++ and Pascal/Delphi one could write something like this:

enum operations {ADD, SUBTRACT, MULTIPLY, DIVIDE };

This would mean that you can declare a variable of type operation. It can only have one of the following values:

Enumeration Value
ADD 0
SUBTRACT 1
MULTIPLY 2
DIVIDE 3

Note that each instance of an operation will have a value of between 0 and 3. This is what makes an enumeration special. It has a value. In reality the compiler only uses the numeric values for constants. You can usually (although I don't encourage it) use the numeric value instead.

In Erlang, an atom is exactly the same - a named constant. It does not have an explicit value, as an enumeration does. You cannot substitute a numeric value for a symbolic one - they are explicitly differnt. The atom ok is different from the atom OK (The one is in lowercase, the other in uppercase).

Each instance of the Erlang Virtual Machine has an Atom Table.


Note: It is important to know that every symbol that starts with a lowercase letter will be interpreted as an atom.
Note: An atom is also indicated by enclosing the symbol in single quotes.

The following symbols are all atoms:

ok
abc
theLetter
'EXIT'
'abc'
'123'

See Also