100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Erlang Cheat Sheet

Erlang Cheat Sheet

Core Erlang syntax covering modules, pattern matching, recursion, and the actor-model process/message-passing primitives.

2 PagesAdvancedMar 28, 2026

Modules & Functions

A minimal Erlang module.

erlang
%% hello.erl-module(hello).-export([world/0]).world() ->    io:format("Hello, World!~n").%% In the shell:%% 1> c(hello).%% 2> hello:world().

Pattern Matching

Single-assignment variables and function clauses.

erlang
%% Variables bind once (single assignment)X = 5,{A, B} = {1, 2},           %% tuple pattern matchfactorial(0) -> 1;factorial(N) when N > 0 -> N * factorial(N - 1).describe({ok, Value}) -> Value;describe({error, Reason}) -> Reason.

Processes & Messages

Spawning lightweight processes and sending messages.

erlang
%% Spawn a process and send it messagesPid = spawn(fun loop/0),Pid ! {self(), hello},loop() ->    receive        {From, hello} ->            From ! {self(), world},            loop();        stop ->            ok    end.

Modules & Attributes

Common module-level declarations.

  • -module(name).- Declares the module; must match the filename
  • -export([f/1]).- Exposes function f with arity 1 publicly
  • -record(point, {x, y}).- Defines a record type
  • io:format("~p~n", [Term])- Print a formatted term followed by a newline
  • spawn/1- Creates a new lightweight process
  • receive ... end- Blocks waiting for a matching message

Data Types

Erlang's built-in term types.

  • Atom- Constant literal, e.g. ok, error, undefined
  • Tuple- Fixed-size grouping, e.g. {ok, Value}
  • List- e.g. [1, 2, 3], built from recursive cons cells
  • Binary- e.g. <<1,2,3>>, a raw byte sequence
  • PID- Process identifier returned by spawn
  • Map- e.g. #{key => value}, a key/value store
Pro Tip

Lean on 'let it crash' — wrap risky work in a supervised process instead of defensive try/catch everywhere; OTP supervisors restart failed processes automatically.

Was this cheat sheet helpful?

Explore Topics

#Erlang#ErlangCheatSheet#Programming#Advanced#ModulesFunctions#PatternMatching#ProcessesMessages#ModulesAttributes#Algorithms#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet