2 Diving In
2.2 Atoms and Strings
2.2.1 Atoms
Atoms are a data type in Erlang that is used to represent non-numerical constants. In LFE, the typographical limitations of Erlang don't apply, since they're always quoted in LFE ;-)
Atoms have a value: the same as their text:
We saw this in the section on Boolean operators with the atoms of true
and false
. Since there are no Boolean types in Erlang or LFE, the atoms
true
and false
are used instead.
Here are some more examples of atoms:
Though very simple, atoms have a huge impact on our everyday use of Erlang and LFE, primarily in the area of pattern matching. Hold that thought, though; we're not quite ready for it yet!
Furthermore, atoms are stored differently in Erlang than strings. They take up less space and are more efficient to compare than strings.
2.2.2 Strings
Now we come to the oddball of Erlang: the string. In truth, there is no such thing. Strings in Erlang are just lists of integers:
Because Erlang (and thus LFE) strings consume 8 bytes per character on 32-bit
systems and 16 bytes on 64-bit systems, they are not very efficient. As such,
if you need to work with long strings in LFE, you probably want to use
(binary ...)
, but that's in the next section :-)