@alepoletto
May 25, 2015
@alepoletto
What is/ Why?• Functional programming language.
• Large emphasis on concurrency and high reliability
• Erlang's runtime system has built-in support for concurrency,
distribution and fault tolerance
• Use the Actor Model
• Used in telecoms, banking, e-commerce, computer telephony and
instant messaging.
• Runs inside a virtual machine.
@alepoletto
Who created?
@alepoletto
Reference to A. K. Erlang
@alepoletto
Who is using
@alepoletto
@alepoletto
Variables and Atoms
• X = 2 + 2.
• X = 4.
• X = 7.
• x = 4. (can’t be lower case)
• Lower case is reserved to atoms
• Lets say that car is a atom.
• Them car is a car nothing more.
• Useful to express values
@alepoletto
Functions
soma(A, B) -> A+B.
ola() -> io:format(“Ola”).
olaSoma(A) -> ola(), soma(A,1).
@alepoletto
Modules
-module(society).
-export([soma/2]).
-compile(export_all).
soma(A, B) -> A+B.
ola() -> io:format(“Ola”).
@alepoletto
Pattern Matcher
@alepoletto
Pattern Matching
function jovem(Pessoa)
if Pessoa == chaves then
print(“Jovem ainda”)
else if Pessoa == madruga then
print(“Velho”)
else
print(“Não sei")
end
@alepoletto
Pattern Matching
jovem(chaves) -> io:format(“Jovem ainda”);
jovem(madruga) -> io:format(“Velho”);
jovem(_) -> io:format(“Não Sei”).
adulto(X) when X >= 21 -> true;
adulto(_) -> false.
@alepoletto
Lets be Functional
fatorial(0) -> 1;
fatorial(N) -> when N > 0 -> N * fatorial(N-1).
map(_, []) -> [];
map(F, [H|T]) -> [F(H)|map(F,T)].
L = [1,2,3,4,5].
map(fun society:fatorial/1, L).
map(fun(X) -> X + 1 end, L).
@alepoletto
Actors
@alepoletto
Actors
cobra() ->receive
{From, speak} ->From ! “You're the disease, and I'm the
cure.";{From, deal} ->
From ! “I don't deal with psychos. I put them away. ";
_ ->io:format(“no talk")
end.
@alepoletto
Actors
Stallone = spawn(society, cobra, []).
<0.55.0>
Stallone! {self(), speak}.
flush().
"You're the disease, and I'm the cure. “
Stallone! {self(), danca}.
flush().
@alepoletto
Actors
cobra() ->receive
{From, speak} ->From ! “You're the disease, and I'm the cure."cobra();
{From, deal} ->From ! “I don't deal with psychos. I put them away. "cobra();
_ ->io:format(“no talk")cobra();
end.
@alepoletto
Actors
Stallone! {self(), speak}.
“You're the disease, and I'm the cure.“
Stallone! {self(), deal}.
“I don't deal with psychos. I put them away. “
Stallone! {self(), shoot}.
“no talk”
@alepoletto
Reference
• http://learnyousomeerlang.com/
• http://www.erlang.org/
• http://en.wikipedia.org/wiki/Erlang_(programming_language)
@alepoletto
Thank You
@alepoletto