erlang
TRANSCRIPT
Erlang – What is it?
- created by Joe Armstrong in 1986 at Ericcsson Telecom- based on Prolog
- functional language- dynamicly typed
Author: Mateusz Zawisza
Where is it used?
- RabbitMQ (France Telecom)- Facebook Chat- GitHub (egitd)
- SampleDB (AWS)
Author: Mateusz Zawisza
Types - variables
Var = 2.Var. %=> 2Var = 3. % this throws an error!
Author: Mateusz Zawisza
Types - atoms
- same role as symbols in Ruby- usually start with lower-case
this_is_atom
Author: Mateusz Zawisza
Types - lists
[1, 2, 3, 4]
Author: Mateusz Zawisza
Types - tuples
{a, 2,"d"}.{ company, {name, "Applicake",
{address, "Krakow"}}
}.
Author: Mateusz Zawisza
MatchingCompany = {company, {name, "Applicake"}, {address, "Krakow"} }.
{company, {name, Name}, {address, Address}} = Company.
Name %=> "Applicake" Address %=> "Krakow"
Author: Mateusz Zawisza
Matching
[Head | Tail] = [1,2,3,4].
Head. %=> 1 Tail. %=> [2,3,4]
Author: Mateusz Zawisza
Matching
[One, Two | Rest] = [1,2,3,4].
One. %=> 1 Two. %=> 2 Rest.%=> [3,4]
Author: Mateusz Zawisza
Functions
-module(mirror_function). -export([mirror/1]).
mirror(Argument) -> Argument.
Author: Mateusz Zawisza
Functions
-module(matching_function). -export([number/1]).
number(one) -> 1; number(two) -> 2; number(three) -> 3.
Author: Mateusz Zawisza
Functions
Numbers = [1,2,3,4].
lists:map(fun(X) -> X+1 end, Numbers). %=> [2,3,4,5]
Author: Mateusz Zawisza
Functions
map(F, [H|T]) -> [F(H) | map(F, T)]; map(F, []) -> [].
Author: Mateusz Zawisza
Control sturctures...
case...
case Animal of "dog" -> underdoga; "cat" -> thundercat _ -> something_elseend.
Author: Mateusz Zawisza
Control sturctures... if...
if X > 0 -> positive; X < 0 -> negative; true -> zeroend.
Author: Mateusz Zawisza
Processes
Pid = spawn(fun module_name:function_name/0).
Pid ! "message".
Author: Mateusz Zawisza
Processes
fuction_name() -> receive "message" -> io:format("Hi!"), function_name(); _ -> io:format("Whatever..."), function_name()end.
Author: Mateusz Zawisza