Variable Assignment
Browse / Erlang Cheatsheet
Erlang Cheatsheet
A quick reference guide to the Erlang programming language, covering syntax, data types, concurrency, and OTP principles.
Erlang Basics
Syntax Fundamentals
|
|
Erlang uses single assignment. Variables start with an uppercase letter.
|
|
Atoms |
Atoms are literal constants, starting with a lowercase letter.
|
|
Comments |
Single-line comments start with
|
|
Tuples |
Tuples are compound data types.
|
|
Lists |
Lists are dynamic arrays.
|
|
Strings |
Strings are lists of character codes.
|
Basic Operators
|
Arithmetic |
|
|
Comparison |
|
|
Boolean |
|
|
List Operators |
|
Concurrency
Processes
|
Spawning Processes |
Use
|
|
Sending Messages |
Use
|
|
Receiving Messages |
Use
|
|
Process Identifiers (PIDs) |
Returned by |
Message Handling
|
Messages are the primary means of communication between Erlang processes. They are asynchronous and can be any Erlang term. |
|
The |
|
Use
|
OTP Principles
Supervisors
|
Supervisors are processes that monitor and restart other processes (children) in case of failure. They ensure the system’s fault tolerance. |
|
Common supervision strategies include |
|
Example:
|
Behaviours
|
|
Generic server behaviour for stateful processes. |
|
|
Generic state machine behaviour. |
|
|
Generic event handler behaviour. |
|
|
Behaviour for creating supervisor processes. |
Applications
|
Applications are a collection of modules, processes, and other resources that form a reusable component. They provide a way to package and manage Erlang code. |
|
An application resource file ( |
Common Built-in Functions (BIFs)
Process Related
|
|
Returns the PID of the current process. |
|
|
Spawns a new process. |
|
|
Terminates the current process with the given reason. |
|
|
Sets up a monitor for the specified process. |
Data Type Conversion
|
|
Converts a list to an atom. |
|
|
Converts an atom to a list. |
|
|
Converts a list to an integer. |
|
|
Converts an integer to a list. |
I/O
|
|
Prints formatted output. |
|
|
Reads the contents of a file. |