Erlang Central

Difference between revisions of "Atom"

From ErlangCentral Wiki

Line 27: Line 27:
  
 
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).
 
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 [[Erlang Virtual Machine]] has an [[Atom Table]]

Revision as of 08:28, 2 September 2006

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 Erlang Virtual Machine has an Atom Table