SlideShare a Scribd company logo
Erlang & Elixir
workshop #1 :: erlang 101
Created by /Krzysztof Marciniak @hun7err
Erlang
You can the introduction.skip
Source:
What is Erlang?
Erlang is a programming language used to build
massively scalable soft real-time systems with
requirements on high availability. Some of its uses
are in telecoms, banking, e-commerce, computer
telephony and instant messaging. Erlang's runtime
system has built-in support for concurrency,
distribution and fault tolerance.
Erlang homepage
Source:
What is Erlang?
Erlang's syntax is very similar to Prolog's, but the
semantics are very different. An early version of
Erlang was written using Prolog, but today's Erlang
can no longer meaningfully be said to be "based
on Prolog."
StackOverflow
Why Erlang?
it's functional!
it's multi-threaded!
high-availability
easy distribution
code hot-swap
Components of Erlang
virtual machine - the new BEAM (Bogdan/Björn's Erlang Abstract
Machine)
OTP - Open Telecom Platform, a framework/library
erl - Erlang interactive console
rebar* - an Erlang build tool [ ]GitHub
* technically it's not an official component, but it is very useful
The absolute basics
-module(ex1).
-export([add/2]).
add(X, Y) ->
X + Y.
1> c(ex1).
{ok,ex1}
2> ex1:add(2, 3).
5
3>
$ erl -man [module_name]
io, lists, etc.
Recursive functions
-module(fac).
-export([fac/1]).
fac(1) ->
1; % function clause
fac(N) ->
N * fac(N - 1).
Higher-order functions
1> X = fun(X) -> X * 4 end.
2> X(4).
16
3>
Lists
[Head | Tail] = [1,2,3,4] % list decomposition
[First, Second | Tail] = [1,2,3,4] % ( ͡° ͜ʖ ͡°)
lists:reverse([1,2,3,4])
lists:append([1,2], [3,4])
lists:append([[1,2],[3,4],[5,6]])
lists:filter(fun(X) -> X rem 2 == 0 end, [1,2,3,4,5,6]) % only even numbers
lists:foldl(fun(X, Sum) -> X + Sum end, 0, [1,2,3,4,5]) % sum
% ^--- fold left, might sound familiar
% erl -man lists
Stop! Hammer time.
(excercises)
1. Create a list_reverse function
2. Write a custom map function (list_map)
Lightweight threads
-module(simplethreads).
-export([start/1]).
hello(Text) ->
io:format("Hello, ~p!~n", [Text]).
start() ->
spawn(simplethreads, hello, ["World"]).
That should return PID of the spawned process, i.e. <0.59.0>
Threads + Recursion =
Awesomeness
-module(threads).
-export([start/0, say/2]).
say(_, 0) ->
done;
say(Text, Times) ->
io:format("~p~n", [Text]),
say(Text, Times-1).
start() ->
spawn(threads, say, ["hello", 5]),
spawn(threads, say, ["bye", 5]).
Interprocess communication
(1/2)
-module(simplethreads).
-export([start/0, say/0]).
say() ->
receive
Text ->
io:format("Hello, ~p!~n", [Text])
end.
start() ->
Pid = spawn(simplethreads, say, []),
timer:sleep(200),
Pid ! "World",
ok.
Interprocess communication
(2/2.1)
-module(pingpong).
-export([start/0]).
ping(0, PongPID) ->
PongPID ! finished,
io:format("ping finished~n", []);
ping(N, PongPID) ->
PongPID ! {ping, self()},
receive
pong ->
io:format("pong~n", [])
end,
ping(N-1, PongPID).
% continued on the next slide
Interprocess communication
(2/2.2)
pong() ->
receive
finished ->
io:format("pong finished~n", []);
{ping, PingPID} ->
io:format("ping~n", []),
PingPID ! pong,
pong()
end.
start() ->
PongPID = spawn(pingpong, pong, []),
spawn(pingpong, ping, [5, PongPID]).
Interprocess communication
Eshell V7.1 (abort with ^G)
1> c(pingpong).
{ok,pingpong}
2> pingpong:start().
ping
<0.42.0>
pong
ping
pong
ping
pong
ping
pong
ping
pong
ping finished
pong finished
3>
OTP - Open Telecom Platform
OTP stands for Open Telecom Platform, although
it's not that much about telecom anymore (it's
more about software that has the property of
telecom applications, but yeah.) If half of Erlang's
greatness comes from its concurrency and
distribution and the other half comes from its
error handling capabilities, then the OTP
framework is the third half of it.
OTP example
-module(server).
-behaviour(myserver).
-export([ % The behaviour callbacks
init/1, % - initializes our process
handle_call/3, % - handles synchronous calls (with response)
handle_cast/2, % - handles asynchronous calls (no response)
handle_info/2, % - handles out of band messages (sent with !)
terminate/2, % - is called on shut-down
code_change/3]). % - called to handle code changes
Elixir
The new youth of Erlang
What is Elixir?
Elixir is a dynamic, functional language designed
for building scalable and maintainable
applications. Elixir leverages the Erlang VM, known
for running low-latency, distributed and fault-
tolerant systems, while also being successfully
used in web development and the embedded
software domain.
The basics
:hello # an atom
"utf string ąę" # in erlang that would not be so easy
hello = "a thing" # no longer capitalized, yay!
hello = :hello # notice how we can overwrite the value
IO.puts("hellonworld")
length([1,2,3]) # I'll speak of lists in a second
length [1,2,3] # notice how we can skip brackets
Lists
iex> a_list = [1,2,3,4,5]
[1,2,3,4,5]
iex> a_list = a_list ++ [6]
[1,2,3,4,5,6]
iex> a_list -- [1,3,5]
[2,4,6]
iex> [head|tail] = [1,2,3,4] # also hd/1, tl/1
[1,2,3,4]
iex> head
1
iex> tail
[2,3,4]
iex> [104, 101, 108, 108, 111]
"hello"
Tuples
iex> tuple = {:ok, "hello"}
{:ok, "hello"}
iex> put_elem(tuple, 1, "world")
{:ok, "world"}
iex> tuple # Elixir types are immutable
{:ok, "hello"}
iex> tuple_size tuple
2
Modules and functions
defmodule Calculator do
def add(x, y) do
x + y
end
end
defmodule Lists do
def reverse([head|tail], acc) do
reverse(tail, [head|acc])
end
# function clauses do not have to be distinguished
def reverse([], acc) do
acc
end
end
If macro, keywords, maps and
dicts
iex> if false, do: :this, else: :that
:that
iex> if(false, [do: :this, else: :that])
:that
iex> if(false, [{:do, :this}, {:else, :that}])
:that
iex> map = %{:a => 1, :b => 2}
%{a: 1, b: 2}
iex> list = [a: 1, b: 3]
[a: 1, b: 3]
iex> Dict.put list, :a, 4
[a: 4, b: 3]
iex> Dict.put map, :a, 4
%{a: 4, b: 2}
Phoenix framework
Phoenix is a web development framework written
in Elixir which implements the server-side MVC
pattern. Many of its components and concepts will
seem familiar to those of us with experience in
other web frameworks like Ruby on Rails or
Python's Django.
Getting started with Phoenix
$ mix local.hex
$ mix archive.install https://github.com/phoenixframework/phoenix/releases/download/v1.1.0/phoen
$ mix phoenix.new hello
$ mix ecto.create
$ mix phoenix.server
Bibliography
The official "Getting started" guide -
Learn You Some Erlang -
Erlang Doc on distributed systems -
OTP for beginners -
Elixir Lang homepage -
Phoenix Framework homepage -
http://www.erlang.org/download/getting_started-5.4.pdf
http://learnyousomeerlang.com/
link
link
http://elixir-lang.org/
http://www.phoenixframework.org/

More Related Content

What's hot (20)

PPTX
Introduction to Phoenix Framework (Elixir) 2016-01-07
Svein Fidjestøl
 
PDF
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Elixir Club
 
PDF
Atmosphere 2014
Jamie Winsor
 
PDF
8 Minutes On Rack
danwrong
 
PDF
Rack Middleware
LittleBIGRuby
 
PDF
Phoenix for Rails Devs
Diacode
 
PDF
Phoenix Framework
Pivorak MeetUp
 
PDF
Pycon - Python for ethical hackers
Mohammad Reza Kamalifard
 
PDF
maXbox Starter 42 Multiprocessing Programming
Max Kleiner
 
PDF
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Habeeb Rahman
 
KEY
Ruby Concurrency and EventMachine
Christopher Spring
 
PDF
Speech for Windows Phone 8
Marco Massarelli
 
PDF
Découvrir dtrace en ligne de commande.
CocoaHeads France
 
PDF
Fluentd v0.12 master guide
N Masahiro
 
PDF
Python, do you even async?
Saúl Ibarra Corretgé
 
PDF
Flask With Server-Sent Event
Tencent
 
PDF
Doing It Wrong with Puppet -
Puppet
 
PDF
Rack
Sarah Allen
 
PPTX
Async programming and python
Chetan Giridhar
 
PDF
Exploring Async PHP (SF Live Berlin 2019)
dantleech
 
Introduction to Phoenix Framework (Elixir) 2016-01-07
Svein Fidjestøl
 
Yaroslav Martsynyuk - Deploying Elixir/Phoenix with Distillery
Elixir Club
 
Atmosphere 2014
Jamie Winsor
 
8 Minutes On Rack
danwrong
 
Rack Middleware
LittleBIGRuby
 
Phoenix for Rails Devs
Diacode
 
Phoenix Framework
Pivorak MeetUp
 
Pycon - Python for ethical hackers
Mohammad Reza Kamalifard
 
maXbox Starter 42 Multiprocessing Programming
Max Kleiner
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Habeeb Rahman
 
Ruby Concurrency and EventMachine
Christopher Spring
 
Speech for Windows Phone 8
Marco Massarelli
 
Découvrir dtrace en ligne de commande.
CocoaHeads France
 
Fluentd v0.12 master guide
N Masahiro
 
Python, do you even async?
Saúl Ibarra Corretgé
 
Flask With Server-Sent Event
Tencent
 
Doing It Wrong with Puppet -
Puppet
 
Async programming and python
Chetan Giridhar
 
Exploring Async PHP (SF Live Berlin 2019)
dantleech
 

Similar to Erlang and Elixir (20)

PDF
Erlang Message Passing Concurrency, For The Win
l xf
 
PDF
Erlang, an overview
Patrick Huesler
 
PDF
Elixir and OTP Apps introduction
Gonzalo Gabriel Jiménez Fuentes
 
PDF
Origins of Elixir programming language
Pivorak MeetUp
 
PPTX
Elixir
Fuat Buğra AYDIN
 
PDF
FunctionalConf '16 Robert Virding Erlang Ecosystem
Robert Virding
 
PDF
Introduction To Erlang Final
SinarShebl
 
PPTX
Elixir introduction
Al Sayed Gamal
 
PDF
Introducing Elixir and OTP at the Erlang BASH
devbash
 
PDF
Erlang is not a city in Germany
momo-13
 
PDF
Getting started erlang
Kwanzoo Dev
 
PPT
Erlang OTP
Zvi Avraham
 
PDF
Elixir talk
Cory Gwin
 
PPT
The Erlang Programming Language
Dennis Byrne
 
PPTX
Repeating History...On Purpose...with Elixir
Barry Jones
 
PDF
Erlang from behing the trenches by Francesco Cesarini
Naresh Jain
 
KEY
Erlang bootstrap course
Martin Logan
 
PDF
Erlang - Concurrent Language for Concurrent World
Zvi Avraham
 
PPTX
Erlang kickstart
Ryan Brown
 
PDF
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ijcd
 
Erlang Message Passing Concurrency, For The Win
l xf
 
Erlang, an overview
Patrick Huesler
 
Elixir and OTP Apps introduction
Gonzalo Gabriel Jiménez Fuentes
 
Origins of Elixir programming language
Pivorak MeetUp
 
FunctionalConf '16 Robert Virding Erlang Ecosystem
Robert Virding
 
Introduction To Erlang Final
SinarShebl
 
Elixir introduction
Al Sayed Gamal
 
Introducing Elixir and OTP at the Erlang BASH
devbash
 
Erlang is not a city in Germany
momo-13
 
Getting started erlang
Kwanzoo Dev
 
Erlang OTP
Zvi Avraham
 
Elixir talk
Cory Gwin
 
The Erlang Programming Language
Dennis Byrne
 
Repeating History...On Purpose...with Elixir
Barry Jones
 
Erlang from behing the trenches by Francesco Cesarini
Naresh Jain
 
Erlang bootstrap course
Martin Logan
 
Erlang - Concurrent Language for Concurrent World
Zvi Avraham
 
Erlang kickstart
Ryan Brown
 
ElixirConf 2017 - Writing an Editor in Elixir - Ian Duggan
ijcd
 
Ad

Recently uploaded (20)

PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Ad

Erlang and Elixir

  • 1. Erlang & Elixir workshop #1 :: erlang 101 Created by /Krzysztof Marciniak @hun7err
  • 2. Erlang You can the introduction.skip
  • 3. Source: What is Erlang? Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecoms, banking, e-commerce, computer telephony and instant messaging. Erlang's runtime system has built-in support for concurrency, distribution and fault tolerance. Erlang homepage
  • 4. Source: What is Erlang? Erlang's syntax is very similar to Prolog's, but the semantics are very different. An early version of Erlang was written using Prolog, but today's Erlang can no longer meaningfully be said to be "based on Prolog." StackOverflow
  • 5. Why Erlang? it's functional! it's multi-threaded! high-availability easy distribution code hot-swap
  • 6. Components of Erlang virtual machine - the new BEAM (Bogdan/Björn's Erlang Abstract Machine) OTP - Open Telecom Platform, a framework/library erl - Erlang interactive console rebar* - an Erlang build tool [ ]GitHub * technically it's not an official component, but it is very useful
  • 7. The absolute basics -module(ex1). -export([add/2]). add(X, Y) -> X + Y. 1> c(ex1). {ok,ex1} 2> ex1:add(2, 3). 5 3> $ erl -man [module_name] io, lists, etc.
  • 8. Recursive functions -module(fac). -export([fac/1]). fac(1) -> 1; % function clause fac(N) -> N * fac(N - 1).
  • 9. Higher-order functions 1> X = fun(X) -> X * 4 end. 2> X(4). 16 3>
  • 10. Lists [Head | Tail] = [1,2,3,4] % list decomposition [First, Second | Tail] = [1,2,3,4] % ( ͡° ͜ʖ ͡°) lists:reverse([1,2,3,4]) lists:append([1,2], [3,4]) lists:append([[1,2],[3,4],[5,6]]) lists:filter(fun(X) -> X rem 2 == 0 end, [1,2,3,4,5,6]) % only even numbers lists:foldl(fun(X, Sum) -> X + Sum end, 0, [1,2,3,4,5]) % sum % ^--- fold left, might sound familiar % erl -man lists
  • 11. Stop! Hammer time. (excercises) 1. Create a list_reverse function 2. Write a custom map function (list_map)
  • 12. Lightweight threads -module(simplethreads). -export([start/1]). hello(Text) -> io:format("Hello, ~p!~n", [Text]). start() -> spawn(simplethreads, hello, ["World"]). That should return PID of the spawned process, i.e. <0.59.0>
  • 13. Threads + Recursion = Awesomeness -module(threads). -export([start/0, say/2]). say(_, 0) -> done; say(Text, Times) -> io:format("~p~n", [Text]), say(Text, Times-1). start() -> spawn(threads, say, ["hello", 5]), spawn(threads, say, ["bye", 5]).
  • 14. Interprocess communication (1/2) -module(simplethreads). -export([start/0, say/0]). say() -> receive Text -> io:format("Hello, ~p!~n", [Text]) end. start() -> Pid = spawn(simplethreads, say, []), timer:sleep(200), Pid ! "World", ok.
  • 15. Interprocess communication (2/2.1) -module(pingpong). -export([start/0]). ping(0, PongPID) -> PongPID ! finished, io:format("ping finished~n", []); ping(N, PongPID) -> PongPID ! {ping, self()}, receive pong -> io:format("pong~n", []) end, ping(N-1, PongPID). % continued on the next slide
  • 16. Interprocess communication (2/2.2) pong() -> receive finished -> io:format("pong finished~n", []); {ping, PingPID} -> io:format("ping~n", []), PingPID ! pong, pong() end. start() -> PongPID = spawn(pingpong, pong, []), spawn(pingpong, ping, [5, PongPID]).
  • 17. Interprocess communication Eshell V7.1 (abort with ^G) 1> c(pingpong). {ok,pingpong} 2> pingpong:start(). ping <0.42.0> pong ping pong ping pong ping pong ping pong ping finished pong finished 3>
  • 18. OTP - Open Telecom Platform OTP stands for Open Telecom Platform, although it's not that much about telecom anymore (it's more about software that has the property of telecom applications, but yeah.) If half of Erlang's greatness comes from its concurrency and distribution and the other half comes from its error handling capabilities, then the OTP framework is the third half of it.
  • 19. OTP example -module(server). -behaviour(myserver). -export([ % The behaviour callbacks init/1, % - initializes our process handle_call/3, % - handles synchronous calls (with response) handle_cast/2, % - handles asynchronous calls (no response) handle_info/2, % - handles out of band messages (sent with !) terminate/2, % - is called on shut-down code_change/3]). % - called to handle code changes
  • 20. Elixir The new youth of Erlang
  • 21. What is Elixir? Elixir is a dynamic, functional language designed for building scalable and maintainable applications. Elixir leverages the Erlang VM, known for running low-latency, distributed and fault- tolerant systems, while also being successfully used in web development and the embedded software domain.
  • 22. The basics :hello # an atom "utf string ąę" # in erlang that would not be so easy hello = "a thing" # no longer capitalized, yay! hello = :hello # notice how we can overwrite the value IO.puts("hellonworld") length([1,2,3]) # I'll speak of lists in a second length [1,2,3] # notice how we can skip brackets
  • 23. Lists iex> a_list = [1,2,3,4,5] [1,2,3,4,5] iex> a_list = a_list ++ [6] [1,2,3,4,5,6] iex> a_list -- [1,3,5] [2,4,6] iex> [head|tail] = [1,2,3,4] # also hd/1, tl/1 [1,2,3,4] iex> head 1 iex> tail [2,3,4] iex> [104, 101, 108, 108, 111] "hello"
  • 24. Tuples iex> tuple = {:ok, "hello"} {:ok, "hello"} iex> put_elem(tuple, 1, "world") {:ok, "world"} iex> tuple # Elixir types are immutable {:ok, "hello"} iex> tuple_size tuple 2
  • 25. Modules and functions defmodule Calculator do def add(x, y) do x + y end end defmodule Lists do def reverse([head|tail], acc) do reverse(tail, [head|acc]) end # function clauses do not have to be distinguished def reverse([], acc) do acc end end
  • 26. If macro, keywords, maps and dicts iex> if false, do: :this, else: :that :that iex> if(false, [do: :this, else: :that]) :that iex> if(false, [{:do, :this}, {:else, :that}]) :that iex> map = %{:a => 1, :b => 2} %{a: 1, b: 2} iex> list = [a: 1, b: 3] [a: 1, b: 3] iex> Dict.put list, :a, 4 [a: 4, b: 3] iex> Dict.put map, :a, 4 %{a: 4, b: 2}
  • 27. Phoenix framework Phoenix is a web development framework written in Elixir which implements the server-side MVC pattern. Many of its components and concepts will seem familiar to those of us with experience in other web frameworks like Ruby on Rails or Python's Django.
  • 28. Getting started with Phoenix $ mix local.hex $ mix archive.install https://github.com/phoenixframework/phoenix/releases/download/v1.1.0/phoen $ mix phoenix.new hello $ mix ecto.create $ mix phoenix.server
  • 29. Bibliography The official "Getting started" guide - Learn You Some Erlang - Erlang Doc on distributed systems - OTP for beginners - Elixir Lang homepage - Phoenix Framework homepage - http://www.erlang.org/download/getting_started-5.4.pdf http://learnyousomeerlang.com/ link link http://elixir-lang.org/ http://www.phoenixframework.org/