September 2013
Intermediate to advanced
548 pages
12h 25m
English
In Erlang, atoms are used to represent constant values.
If you are used to enumerated types in C or Java, or symbols in Scheme or Ruby, then you will have already used something very similar to atoms.
C programmers will be familiar with the convention of using symbolic constants to make their programs self-documenting. A typical C program will define a set of global constants in an include file that consists of a large number of constant definitions; for example, there might be a file glob.h containing this:
| | #define OP_READ 1 |
| | #define OP_WRITE 2 |
| | #define OP_SEEK 3 |
| | ... |
| | #define RET_SUCCESS 223 |
| | ... |
Typical C code using such symbolic constants might read as follows:
| | #include "glob.h" |
| | int ret; |
| | ret = file_operation(OP_READ, buff); ... |
Read now
Unlock full access