Meet common terms: full examples and further reading
The original lesson material is preserved here for reference. The main notebook focuses on this lesson's core question.
Learn numbers, atoms, tuples, lists, and maps.
Run a number, atom, tuple, list, and map in erl, then compare the shapes of their results.
Look at terms in erl
Look at each shape, then use an is_* function to check it.
%% Check numbers and atoms
{is_integer(12), is_float(12.5)}.
{is_atom(true), is_atom(ok)}.
%% Run a tuple and a list
{ok, 42}.
[peach, plum, apricot].
%% Run a map whose atom keys explain its values
#{status => ready, score => 92}.The first two lines both return {true, true}.
The next two lines show the tuple {ok, 42} and the list [peach, plum, apricot].
The final line shows a map with the keys status and score.
Steps for the full example
is_integer(12)andis_float(12.5)each inspect one value and return true or false.trueis the atom commonly used to mean yes. Its type is still atom.#{...}creates a map. Herestatus,ready, andscoreare labels from a limited set.
Original lesson notes
Erlang calls every piece of runtime data a term. Numbers, atoms, tuples, lists, and maps are all terms.
A word that begins with a lowercase letter is usually an atom, such as ok or rain. In Erlang, true and false are atoms too.
Erlang has no built-in nil value. A project may choose undefined, none, or another atom to mean “missing,” but the project should state that rule.
Symbols and terms
ok- It begins with a lowercase letter, so it is an atom label.
{ok, 42}- A two-item tuple. The first atom often labels the kind of result.
#{status => ready}- A map.
=>joins a key to a value. - term
- Erlang's general name for runtime data. Different terms have different shapes and jobs.
- atom
- A label usually written as a lowercase word, such as
ok. Its name is its value. - tuple
- A fixed group inside braces, such as
{ok, 42}.
Original full exercise
Complete a weather map. Use an atom for the weather and an integer for the temperature.
%% Use weather and temperature as the keys
#{____ => cloudy, ____ => 28}.The result should be #{weather => cloudy, temperature => 28}.
Show hint
Fill the blanks with the atoms weather and temperature.
Show original answer
%% Atom keys explain what the two values mean
#{weather => cloudy, temperature => 28}.Is true a separate type in Erlang?
No. true is an atom that people agree to use for a true result.
Original lesson takeaways
- Erlang calls all runtime data terms.
- Atoms are useful for a limited set of labels such as
ok,ready, andcloudy. - Tuples and maps both hold several values, but maps give fields names.