Erlang
-
Upload
mateuszzawisza -
Category
Documents
-
view
345 -
download
1
Transcript of Erlang
Erlang
What is it?
created by Joe Armstrong in 1986 at Ericcsson Telecom
based on Prolog
functional language
dynamicly typed
Erlang is...
reliable
high concurrent (no threads. light processes)
modular
Where is it used?
RabbitMQ (France telecom)
CouchDB
Facebook Chat
GitHub (egitd)
SimpleDB (AWS)
Types
Variables
Var = 2.
Var.%=> 2
Var = 3. % this throws an error!
atoms
this_is_atom
Lists
[1,2,3,4]
Tuples
{a, 2,"d"}.
{ company, {name, "Applicake", {address, "Krakow"}}}.
Matching
Company = {company, {name, "Applicake"}, {address, "Krakow"} }.
{company, {name, Name, {address, Address}}} = Company.
Name %=> "Applicake"Address %=> "Krakow"
Matching
[Head | Tail] = [1,2,3,4].
Head. %=> 1Tail. %=> [2,3,4]
Matching
[One, Two | Rest] = [1,2,3,4].
One. %=> 1Two. %=> 2Rest.%=> [3,4]
functions
-module(mirror_function).-export([mirror/1]).
mirror(Argument) -> Argument.
functions
-module(matching_function).-export([number/1]).
number(one) -> 1;number(two) -> 2; number(three) -> 3.
functions
Numbers = [1,2,3,4].
lists:map(fun(X) -> X+1 end, Numbers).%=> [2,3,4,5]
functions
map(F, [H|T]) -> [F(H) | map(F, T)];map(F, []) -> [].
Control structures
case...
case Animal of "dog" -> underdoga; "cat" -> thundercat _ -> something_else end.
Control structures
if...
if X > 0 -> positive; X < 0 -> negative; true -> zeroend.
Processes
Processes
Pid = spawn(fun module_name:function_name/0).
Pid ! "message".
Processes
fuction_name() -> receive "message" -> io::format("Hi!"), function_name();
_ -> io::format("Whatever..."), function_name()
end.