Terms and Variables
- Terms. Every Erlang value is a term: integers, atoms, tuples, lists, maps, binaries, pids.
- Atoms. An atom is a literal constant: ok, error, undefined: the vocabulary of every return value.
- Single assignment. Variables bind once: X = 5 forever in that scope; rebinding is a match error, not an update.
Pattern Matching
- Match, not assign. The equals sign is a match: {ok, Value} = parse(Line) binds by shape or crashes honestly.
- Destructuring. Matching destructures: heads of lists, elements of tuples: data pulled apart by shape.
- Match as control flow. Function clauses match in order: the first clause whose patterns fit runs, the rest never do.
Functions and Modules
- Modules. Code lives in modules: -module(billing).: with -export listing the public functions.
- Function clauses. A function is a set of clauses: area({circle, R}) and area({square, S}): dispatch by pattern.
- Arity matters. Functions are named with arity: sum/1 and sum/2 are different functions entirely.
Before and after this level
- Before: Start Here: Let It Crash: BEAM Virtual Machine, Concurrency and Fault Tolerance.
- Next: Level 2: Functional Erlang: Recursion, Lists and Higher-Order Functions, Immutable Data Transformation.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Erlang Level 1: Erlang Foundations cover?
Terms and Variables, Pattern Matching, Functions and Modules: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Start Here: Let It Crash, which covers BEAM Virtual Machine, Concurrency and Fault Tolerance.