SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
Introduction to Erlang
            Gabriele Lana
      gabriele.lana@gmail.com
Why Erlang?




   Damien Katz @ Ruby Fringe 2008
Erlang Shell


Erlang (BEAM) emulator version 5.5.6 [source]
[smp:1] [async-threads:0] [hipe] [kernel-poll:true]

Eshell V5.5.6 (abort with ^G)
1>
Syntax: Number

1> 3.
3

2> 1 + 2008.
2009

3> 849274893217458392017483921 *
78932489321748392107483291.
6703538144011604048584954184722646309721233336866
4011
Syntax: Atom


1> atom.
atom

2> anythingStartingWithLowercaseLetter.
anythingStartingWithLowercaseLetter

3> 'anything enclosed in single quotes'.
'anything enclosed in single quotes'
Syntax: Boolean

1> true.
true

2> false.
false

3> is_atom(true).
true

4> is_boolean(true).
true
Syntax: String



1> quot;fooquot;.
quot;fooquot;

2> quot;anything enclosed in double quotesquot;.
quot;anything enclosed in double quotesquot;
Syntax: List
1> [].
[]

2> [ 1 ].
[1]

3> [ first ].
[first]

4> [ quot;firstquot; ].
[quot;firstquot;]

5> [ 1, first, quot;firstquot; ].
[1,first,quot;firstquot;]
Syntax: Strings are Lists


1> [ 72, 101, 108, 108, 111 ].
quot;Helloquot;

2> $H.
72

3> [ $H, $e, $l, $l, $o ].
quot;Helloquot;
Syntax: Tuple


1> { 1, 2, 3 }.
{1,2,3}

2> { name, quot;Gabrielequot; }.
{name,quot;Gabrielequot;}

3> { coder, { name, quot;Gabrielequot; }, { language, quot;Erlangquot; } }.
{coder,{name,quot;Gabrielequot;},{language,quot;Erlangquot;}}
Pattern Matching


1> 1 = 1.
1

2> 1 = 2.
** exception error: no match of right hand side value 2

3> catch 1 = 2.
{'EXIT',{{badmatch,2},[{erl_eval,expr,3}]}}
Pattern Matching: Binding Variables

1> X.
* 1: variable 'X' is unbound

2> X = 5.
5

3> X.
5

4> X = 6.
** exception error: no match of right hand side value 6
Pattern Matching: Destructuring

1> Coder = { coder, { name, quot;Gabrielequot; } }.
{coder,{name,quot;Gabrielequot;}}

2> { person, { name, PersonName } } = Coder.
** exception error: no match of right hand side value {coder,
{name,quot;Gabrielequot;}}

3> { coder, { name, quot;Gabrielequot; } } = Coder.
{coder,{name,quot;Gabrielequot;}}

4> { coder, { name, CoderName } } = Coder.
{coder,{name,quot;Gabrielequot;}}
Pattern Matching: Destructuring


7> AnotherCoderName = quot;Matteoquot;.
quot;Matteoquot;

8> { coder, { name, AnotherCoderName } } = Coder.
** exception error: no match of right hand side value {coder,
{name,quot;Gabrielequot;}}
Pattern Matching: List


1> [ First, Last ] = [ first, last ].
[first,last]

2> First.
first

3> Last.
last
Pattern Matching: List


4> [ Head | Tail ] = [ 1, 2, 3, 4, 5 ].
[1,2,3,4,5]

5> Head.
1

6> Tail.
[2,3,4,5]
Pattern Matching: List

1> [ First, Second | Others ] = [ 1, 2, 3, 4, 5 ].
[1,2,3,4,5]

2> First.
1

3> Second.
2

4> Others.
[3,4,5]
Pattern Matching: In Deep


1> { X, Y, X } = { { abc, 12 }, 42, { abc, 12 } }.
{{abc,12},42,{abc,12}}

2> X.
{abc,12}

3> Y.
42
Pattern Matching: In Deep


1> { X, Y, X } = { { abc, 12 }, 42, true }.
** exception error: no match of right hand side value {{abc,
12},42,true}

2> { X, Y, _ } = { { abc, 12 }, 42, true }.
{{abc,12},42,true}
Function

-module(examples).
-export([ hello/0 ]).

hello() -> quot;Hello World!quot;.


1> c(examples).
{ok,examples}

2> examples:hello().
quot;Hello World!quot;
Syntax: Punctuation



• Periods (.) end everything except when
• Semicolons (;) end clauses
• and Commas (,) separate expressions
Function: Pattern Mathing & Clause

-export([ double/1 ]).

double(0) -> 0;
double(Number) -> Number * 2.



1> examples:double(0).
0

2> examples:double(4).
8
Function: Guard

double(0) -> 0;
double(Number) when is_integer(Number) ->
 Number * 2.



1> examples:double(4).
8

2> examples:double(foo).
** exception error: no function clause matching
examples:double(foo)
Function: Guard
double(0) -> 0;
double(Number) when is_integer(Number) ->
 Number * 2;
double(AnythingElse) ->
 io:format(quot;I don't know how to double ~p~nquot;,
   [ AnythingElse ]),
 error.


1> examples:double(foo).
I don't know how to double foo
error
Function: Anonymous & Closure
multiplyBy(Multiplier) ->
 fun(Number) ->
  Number * Multiplier
 end.

1> Double = examples:multiplyBy(2).
#Fun<examples.0.46516809>
2> Double(4).
8
3> MultiplyBy4 = examples:multiplyBy(4).
#Fun<examples.0.46516809>
4> MultiplyBy4(4).
16
Function: Tail Recursion
printList([]) ->
 ok;
printList([ Item | List ]) ->
 io:format(quot;~p~nquot;, [ Item ]),
 printList(List).

1> examples:printList([ 1, 2, 3, 4 ]).
1
2
3
4
ok
Function: High Order Function
foreach(_Function, []) ->
 ok;
foreach(Function, [ Item | List ]) ->
 Function(Item),
 foreach(Function, List).

1> examples:foreach(
fun(Item) -> io:format(quot;~p~nquot;, [ Item ])
end, [ 1, 2, 3, 4 ]).
1
2
3
4
Function: High Order Function

foreach(Function, List) ->
 lists:foreach(Function, List).


1> examples:foreach(
fun(Item) -> io:format(quot;~p~nquot;, [ Item ])
end, [ 1, 2, 3, 4 ]).
1
2
3
4
ok
Function: High Order Function


3> lists:foreach(
fun(Item) -> io:format(quot;~p~nquot;, [ Item ])
end, [ 1, 2, 3, 4 ]).
1
2
3
4
ok
List Functions: Map

names(Coders) ->
 lists:map(fun({ coder, { name, CoderName } }) ->
   CoderName
 end, Coders).



1> examples:names([
1> { coder, { name, quot;Gabrielequot; } },
1> { coder, { name, quot;Matteoquot; } }
1> ]).
[quot;Gabrielequot;,quot;Matteoquot;]
Syntax: List Comprehension
triplets(UpTo) when is_number(UpTo), UpTo >= 2 -> [
 { A, B, C } ||
   A <- lists:seq(2, UpTo),
   B <- lists:seq(2, UpTo),
   C <- lists:seq(2, UpTo),
   A * A + B * B =:= C * C
 ].


1> examples:triplets(10).
[{3,4,5},{4,3,5},{6,8,10},{8,6,10}]
List Functions: Fold/Reduce

sum(Numbers) ->
 lists:foldl(fun(Number, Sum) ->
   Sum + Number
 end, 0, Numbers).




1> examples:sum([ 1, 2, 3, 4, 5 ]).
15
List Functions: Fold/Reduce
sum(Numbers) ->
 lists:foldl(fun
   (Number, Sum) when is_integer(Number) ->
    Sum + Number;
   (_Number, Sum) ->
    Sum
 end, 0, Numbers).


1> examples:sum([ 1, 2, 3, foo, 4, bar, 5 ]).
15
Example: FizzBuzz
fizzbuzz(UpTo) ->
 lists:map(fun(Counter) ->
   if
     (Counter rem 15) =:= 0 -> fizzbuzz;
     (Counter rem 3) =:= 0 -> fizz;
     (Counter rem 5) =:= 0 -> buzz;
     true -> Counter
   end
 end, lists:seq(1, UpTo)).

1> examples:fizzbuzz(16).
[1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16]
Process: Concurrency

• Any function (named or anonymous) can
  become a process
• A process is simply a function executing in
  parallel
• A process shares nothing with other processes
• A process is extremely lightweight: a modern
  systems can accommodate literally millions of
  Erlang processes
Process: Concurrency

1> processes:profileSpawnFor(1000).
Spawned 1000 processes in 10 (4) milliseconds
ok

2> processes:profileSpawnFor(10000).
Spawned 10000 processes in 40 (96) milliseconds
ok

3> processes:profileSpawnFor(100000).
Spawned 100000 processes in 510 (884) milliseconds
ok
Process: Concurrency
Process: Concurrency


• The “!” operator sends messages
  • Asynchronous
  • Order guaranted
• The “receive” statement matches messages
  • One call to receive, one message removed
   from the process message queue
 • Uses pattern matching to select messages
Process: Concurrency


1> Pid = spawn(fun() ->
1> receive
1> die -> io:format(quot;Bye~nquot;)
1> end
1> end).
<0.33.0>
Process: Concurrency


2> is_process_alive(Pid).
true

3> Pid ! die.
Bye
die

4> is_process_alive(Pid).
false
Process: Concurrency
profileSpawnFor(Number) ->
 Processes = for(1, Number, fun() ->
   spawn(fun() -> wait() end)
 end),
 lists:foreach(fun(Pid) ->
   Pid ! die
 end, Processes).

wait() ->
 receive
  die -> void
 end.
Process: Fault Tollerance



• The “link” function can link processes
• When a process die the linked processes
  receive a message { ‘EXIT’, Died, Reason }
• A monitor process could respawn the died
  ones or cleanup the system
Process: Distributed




• The spawn(Node, Function) can spawn a
  process in any other known nodes
• No other changes are required!!!
Hard Gained Insights



• Don’t miss tail-call recursion
• Asynchronous is good
• Small functions are good
• When in doubt create a new process
• Think early what to do when a process die
Disco
                           (Map/Reduce with
                            Erlang + Python)



      Yaws
(Yet Another Web Server)

               eJabbered
                  (jabber/XMPP)

Contenu connexe

Tendances

The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.5.4 book - Part 27 of 185The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.5.4 book - Part 27 of 185Mahmoud Samir Fayed
 
DRYing to Monad in Java8
DRYing to Monad in Java8DRYing to Monad in Java8
DRYing to Monad in Java8Dhaval Dalal
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Dhaval Dalal
 
The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.5.1 book - Part 9 of 180The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.5.1 book - Part 9 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181Mahmoud Samir Fayed
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovymanishkp84
 
Expression trees in c#
Expression trees in c#Expression trees in c#
Expression trees in c#Oleksii Holub
 
Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)Alina Vilk
 
Transaction is a monad
Transaction is a  monadTransaction is a  monad
Transaction is a monadJarek Ratajski
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerMario Fusco
 
FizzBuzz Guided Kata
FizzBuzz Guided KataFizzBuzz Guided Kata
FizzBuzz Guided KataMike Clement
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84Mahmoud Samir Fayed
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardMario Fusco
 

Tendances (20)

The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.5.4 book - Part 27 of 185The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.5.4 book - Part 27 of 185
 
DRYing to Monad in Java8
DRYing to Monad in Java8DRYing to Monad in Java8
DRYing to Monad in Java8
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)
 
Strings and Characters
Strings and CharactersStrings and Characters
Strings and Characters
 
The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31
 
The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.5.1 book - Part 9 of 180The Ring programming language version 1.5.1 book - Part 9 of 180
The Ring programming language version 1.5.1 book - Part 9 of 180
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
 
Expression trees in c#
Expression trees in c#Expression trees in c#
Expression trees in c#
 
Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)Expression trees in c#, Алексей Голубь (Svitla Systems)
Expression trees in c#, Алексей Голубь (Svitla Systems)
 
Transaction is a monad
Transaction is a  monadTransaction is a  monad
Transaction is a monad
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
FizzBuzz Guided Kata
FizzBuzz Guided KataFizzBuzz Guided Kata
FizzBuzz Guided Kata
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Pure kotlin
Pure kotlinPure kotlin
Pure kotlin
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 

En vedette

Erlang: the language and the platform
Erlang: the language and the platformErlang: the language and the platform
Erlang: the language and the platformGabriele Lana
 
Resource Oriented Architectures
Resource Oriented ArchitecturesResource Oriented Architectures
Resource Oriented ArchitecturesGabriele Lana
 
Professional Programmer (3 Years Later)
Professional Programmer (3 Years Later)Professional Programmer (3 Years Later)
Professional Programmer (3 Years Later)Gabriele Lana
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to ErlangKirinDave
 
Productivity Gains in Erlang
Productivity Gains in ErlangProductivity Gains in Erlang
Productivity Gains in ErlangJan Henry Nystrom
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsTorben Hoffmann
 
1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTP1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTPJordi Llonch
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlangMirko Bonadei
 
Concurrency And Erlang
Concurrency And ErlangConcurrency And Erlang
Concurrency And Erlangl xf
 
Everybody Polyglot! - Cross-Language RPC with Erlang
Everybody Polyglot! - Cross-Language RPC with ErlangEverybody Polyglot! - Cross-Language RPC with Erlang
Everybody Polyglot! - Cross-Language RPC with ErlangRusty Klophaus
 
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013Wooga
 
Erlang For Five Nines
Erlang For Five NinesErlang For Five Nines
Erlang For Five NinesBarcamp Cork
 

En vedette (20)

MongoDB With Style
MongoDB With StyleMongoDB With Style
MongoDB With Style
 
Erlang: the language and the platform
Erlang: the language and the platformErlang: the language and the platform
Erlang: the language and the platform
 
Nosql
NosqlNosql
Nosql
 
Magic of Ruby
Magic of RubyMagic of Ruby
Magic of Ruby
 
Resource Oriented Architectures
Resource Oriented ArchitecturesResource Oriented Architectures
Resource Oriented Architectures
 
Professional Programmer (3 Years Later)
Professional Programmer (3 Years Later)Professional Programmer (3 Years Later)
Professional Programmer (3 Years Later)
 
Beyond Phoenix
Beyond PhoenixBeyond Phoenix
Beyond Phoenix
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Erlang/OTP in Riak
Erlang/OTP in RiakErlang/OTP in Riak
Erlang/OTP in Riak
 
Productivity Gains in Erlang
Productivity Gains in ErlangProductivity Gains in Erlang
Productivity Gains in Erlang
 
NDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business NeedsNDC London 2014: Erlang Patterns Matching Business Needs
NDC London 2014: Erlang Patterns Matching Business Needs
 
High Performance Erlang
High  Performance  ErlangHigh  Performance  Erlang
High Performance Erlang
 
Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
 
1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTP1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTP
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlang
 
Concurrency And Erlang
Concurrency And ErlangConcurrency And Erlang
Concurrency And Erlang
 
Everybody Polyglot! - Cross-Language RPC with Erlang
Everybody Polyglot! - Cross-Language RPC with ErlangEverybody Polyglot! - Cross-Language RPC with Erlang
Everybody Polyglot! - Cross-Language RPC with Erlang
 
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
A Beginners Guide to Erlang_Erlang Factory Lite_Munich 2013
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Erlang For Five Nines
Erlang For Five NinesErlang For Five Nines
Erlang For Five Nines
 

Similaire à Introduction to Erlang

Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3guesta3202
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor ConcurrencyAlex Miller
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de RailsFabio Akita
 
Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlangasceth
 
Intro python
Intro pythonIntro python
Intro pythonkamzilla
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介Wen-Tien Chang
 
My First Rails Plugin - Usertext
My First Rails Plugin - UsertextMy First Rails Plugin - Usertext
My First Rails Plugin - Usertextfrankieroberto
 
Functional Concepts for OOP Developers
Functional Concepts for OOP DevelopersFunctional Concepts for OOP Developers
Functional Concepts for OOP Developersbrweber2
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallySean Cribbs
 
F# Presentation
F# PresentationF# Presentation
F# Presentationmrkurt
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin IGuixing Bai
 
Elixir formatter Internals
Elixir formatter InternalsElixir formatter Internals
Elixir formatter InternalsPedro Medeiros
 

Similaire à Introduction to Erlang (20)

Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
 
Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlang
 
Intro python
Intro pythonIntro python
Intro python
 
Ruby 程式語言簡介
Ruby 程式語言簡介Ruby 程式語言簡介
Ruby 程式語言簡介
 
Pythonic Math
Pythonic MathPythonic Math
Pythonic Math
 
My First Rails Plugin - Usertext
My First Rails Plugin - UsertextMy First Rails Plugin - Usertext
My First Rails Plugin - Usertext
 
Austen x talk
Austen x talkAusten x talk
Austen x talk
 
Functional Concepts for OOP Developers
Functional Concepts for OOP DevelopersFunctional Concepts for OOP Developers
Functional Concepts for OOP Developers
 
About Go
About GoAbout Go
About Go
 
Groovy
GroovyGroovy
Groovy
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing Functionally
 
F# Presentation
F# PresentationF# Presentation
F# Presentation
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Elixir formatter Internals
Elixir formatter InternalsElixir formatter Internals
Elixir formatter Internals
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 

Plus de Gabriele Lana

Microservice Architectures
Microservice ArchitecturesMicroservice Architectures
Microservice ArchitecturesGabriele Lana
 
Professional Programmer 2018
Professional Programmer 2018Professional Programmer 2018
Professional Programmer 2018Gabriele Lana
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With ElixirGabriele Lana
 
Resource Oriented Design
Resource Oriented DesignResource Oriented Design
Resource Oriented DesignGabriele Lana
 
Agileday Coderetreat 2013
Agileday Coderetreat 2013Agileday Coderetreat 2013
Agileday Coderetreat 2013Gabriele Lana
 
Milano Legacy Coderetreat 2013
Milano Legacy Coderetreat 2013Milano Legacy Coderetreat 2013
Milano Legacy Coderetreat 2013Gabriele Lana
 
Minimum Viable Product
Minimum Viable ProductMinimum Viable Product
Minimum Viable ProductGabriele Lana
 
Professional Programmer
Professional ProgrammerProfessional Programmer
Professional ProgrammerGabriele Lana
 
It is not supposed to fly but it does
It is not supposed to fly but it doesIt is not supposed to fly but it does
It is not supposed to fly but it doesGabriele Lana
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartGabriele Lana
 
Sustainable Agile Development
Sustainable Agile DevelopmentSustainable Agile Development
Sustainable Agile DevelopmentGabriele Lana
 

Plus de Gabriele Lana (18)

Microservice Architectures
Microservice ArchitecturesMicroservice Architectures
Microservice Architectures
 
Professional Programmer 2018
Professional Programmer 2018Professional Programmer 2018
Professional Programmer 2018
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With Elixir
 
Resource Oriented Design
Resource Oriented DesignResource Oriented Design
Resource Oriented Design
 
Agileday Coderetreat 2013
Agileday Coderetreat 2013Agileday Coderetreat 2013
Agileday Coderetreat 2013
 
Milano Legacy Coderetreat 2013
Milano Legacy Coderetreat 2013Milano Legacy Coderetreat 2013
Milano Legacy Coderetreat 2013
 
Minimum Viable Product
Minimum Viable ProductMinimum Viable Product
Minimum Viable Product
 
API Over HTTP
API Over HTTPAPI Over HTTP
API Over HTTP
 
coderetreat
coderetreatcoderetreat
coderetreat
 
Professional Programmer
Professional ProgrammerProfessional Programmer
Professional Programmer
 
It is not supposed to fly but it does
It is not supposed to fly but it doesIt is not supposed to fly but it does
It is not supposed to fly but it does
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Why couchdb is cool
Why couchdb is coolWhy couchdb is cool
Why couchdb is cool
 
ProgrammingKatas
ProgrammingKatasProgrammingKatas
ProgrammingKatas
 
CouchDB Vs MongoDB
CouchDB Vs MongoDBCouchDB Vs MongoDB
CouchDB Vs MongoDB
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
Sustainable Agile Development
Sustainable Agile DevelopmentSustainable Agile Development
Sustainable Agile Development
 

Dernier

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

Introduction to Erlang

  • 1. Introduction to Erlang Gabriele Lana gabriele.lana@gmail.com
  • 2. Why Erlang? Damien Katz @ Ruby Fringe 2008
  • 3. Erlang Shell Erlang (BEAM) emulator version 5.5.6 [source] [smp:1] [async-threads:0] [hipe] [kernel-poll:true] Eshell V5.5.6 (abort with ^G) 1>
  • 4. Syntax: Number 1> 3. 3 2> 1 + 2008. 2009 3> 849274893217458392017483921 * 78932489321748392107483291. 6703538144011604048584954184722646309721233336866 4011
  • 5. Syntax: Atom 1> atom. atom 2> anythingStartingWithLowercaseLetter. anythingStartingWithLowercaseLetter 3> 'anything enclosed in single quotes'. 'anything enclosed in single quotes'
  • 6. Syntax: Boolean 1> true. true 2> false. false 3> is_atom(true). true 4> is_boolean(true). true
  • 7. Syntax: String 1> quot;fooquot;. quot;fooquot; 2> quot;anything enclosed in double quotesquot;. quot;anything enclosed in double quotesquot;
  • 8. Syntax: List 1> []. [] 2> [ 1 ]. [1] 3> [ first ]. [first] 4> [ quot;firstquot; ]. [quot;firstquot;] 5> [ 1, first, quot;firstquot; ]. [1,first,quot;firstquot;]
  • 9. Syntax: Strings are Lists 1> [ 72, 101, 108, 108, 111 ]. quot;Helloquot; 2> $H. 72 3> [ $H, $e, $l, $l, $o ]. quot;Helloquot;
  • 10. Syntax: Tuple 1> { 1, 2, 3 }. {1,2,3} 2> { name, quot;Gabrielequot; }. {name,quot;Gabrielequot;} 3> { coder, { name, quot;Gabrielequot; }, { language, quot;Erlangquot; } }. {coder,{name,quot;Gabrielequot;},{language,quot;Erlangquot;}}
  • 11. Pattern Matching 1> 1 = 1. 1 2> 1 = 2. ** exception error: no match of right hand side value 2 3> catch 1 = 2. {'EXIT',{{badmatch,2},[{erl_eval,expr,3}]}}
  • 12. Pattern Matching: Binding Variables 1> X. * 1: variable 'X' is unbound 2> X = 5. 5 3> X. 5 4> X = 6. ** exception error: no match of right hand side value 6
  • 13. Pattern Matching: Destructuring 1> Coder = { coder, { name, quot;Gabrielequot; } }. {coder,{name,quot;Gabrielequot;}} 2> { person, { name, PersonName } } = Coder. ** exception error: no match of right hand side value {coder, {name,quot;Gabrielequot;}} 3> { coder, { name, quot;Gabrielequot; } } = Coder. {coder,{name,quot;Gabrielequot;}} 4> { coder, { name, CoderName } } = Coder. {coder,{name,quot;Gabrielequot;}}
  • 14. Pattern Matching: Destructuring 7> AnotherCoderName = quot;Matteoquot;. quot;Matteoquot; 8> { coder, { name, AnotherCoderName } } = Coder. ** exception error: no match of right hand side value {coder, {name,quot;Gabrielequot;}}
  • 15. Pattern Matching: List 1> [ First, Last ] = [ first, last ]. [first,last] 2> First. first 3> Last. last
  • 16. Pattern Matching: List 4> [ Head | Tail ] = [ 1, 2, 3, 4, 5 ]. [1,2,3,4,5] 5> Head. 1 6> Tail. [2,3,4,5]
  • 17. Pattern Matching: List 1> [ First, Second | Others ] = [ 1, 2, 3, 4, 5 ]. [1,2,3,4,5] 2> First. 1 3> Second. 2 4> Others. [3,4,5]
  • 18. Pattern Matching: In Deep 1> { X, Y, X } = { { abc, 12 }, 42, { abc, 12 } }. {{abc,12},42,{abc,12}} 2> X. {abc,12} 3> Y. 42
  • 19. Pattern Matching: In Deep 1> { X, Y, X } = { { abc, 12 }, 42, true }. ** exception error: no match of right hand side value {{abc, 12},42,true} 2> { X, Y, _ } = { { abc, 12 }, 42, true }. {{abc,12},42,true}
  • 20. Function -module(examples). -export([ hello/0 ]). hello() -> quot;Hello World!quot;. 1> c(examples). {ok,examples} 2> examples:hello(). quot;Hello World!quot;
  • 21. Syntax: Punctuation • Periods (.) end everything except when • Semicolons (;) end clauses • and Commas (,) separate expressions
  • 22. Function: Pattern Mathing & Clause -export([ double/1 ]). double(0) -> 0; double(Number) -> Number * 2. 1> examples:double(0). 0 2> examples:double(4). 8
  • 23. Function: Guard double(0) -> 0; double(Number) when is_integer(Number) -> Number * 2. 1> examples:double(4). 8 2> examples:double(foo). ** exception error: no function clause matching examples:double(foo)
  • 24. Function: Guard double(0) -> 0; double(Number) when is_integer(Number) -> Number * 2; double(AnythingElse) -> io:format(quot;I don't know how to double ~p~nquot;, [ AnythingElse ]), error. 1> examples:double(foo). I don't know how to double foo error
  • 25. Function: Anonymous & Closure multiplyBy(Multiplier) -> fun(Number) -> Number * Multiplier end. 1> Double = examples:multiplyBy(2). #Fun<examples.0.46516809> 2> Double(4). 8 3> MultiplyBy4 = examples:multiplyBy(4). #Fun<examples.0.46516809> 4> MultiplyBy4(4). 16
  • 26. Function: Tail Recursion printList([]) -> ok; printList([ Item | List ]) -> io:format(quot;~p~nquot;, [ Item ]), printList(List). 1> examples:printList([ 1, 2, 3, 4 ]). 1 2 3 4 ok
  • 27. Function: High Order Function foreach(_Function, []) -> ok; foreach(Function, [ Item | List ]) -> Function(Item), foreach(Function, List). 1> examples:foreach( fun(Item) -> io:format(quot;~p~nquot;, [ Item ]) end, [ 1, 2, 3, 4 ]). 1 2 3 4
  • 28. Function: High Order Function foreach(Function, List) -> lists:foreach(Function, List). 1> examples:foreach( fun(Item) -> io:format(quot;~p~nquot;, [ Item ]) end, [ 1, 2, 3, 4 ]). 1 2 3 4 ok
  • 29. Function: High Order Function 3> lists:foreach( fun(Item) -> io:format(quot;~p~nquot;, [ Item ]) end, [ 1, 2, 3, 4 ]). 1 2 3 4 ok
  • 30. List Functions: Map names(Coders) -> lists:map(fun({ coder, { name, CoderName } }) -> CoderName end, Coders). 1> examples:names([ 1> { coder, { name, quot;Gabrielequot; } }, 1> { coder, { name, quot;Matteoquot; } } 1> ]). [quot;Gabrielequot;,quot;Matteoquot;]
  • 31. Syntax: List Comprehension triplets(UpTo) when is_number(UpTo), UpTo >= 2 -> [ { A, B, C } || A <- lists:seq(2, UpTo), B <- lists:seq(2, UpTo), C <- lists:seq(2, UpTo), A * A + B * B =:= C * C ]. 1> examples:triplets(10). [{3,4,5},{4,3,5},{6,8,10},{8,6,10}]
  • 32. List Functions: Fold/Reduce sum(Numbers) -> lists:foldl(fun(Number, Sum) -> Sum + Number end, 0, Numbers). 1> examples:sum([ 1, 2, 3, 4, 5 ]). 15
  • 33. List Functions: Fold/Reduce sum(Numbers) -> lists:foldl(fun (Number, Sum) when is_integer(Number) -> Sum + Number; (_Number, Sum) -> Sum end, 0, Numbers). 1> examples:sum([ 1, 2, 3, foo, 4, bar, 5 ]). 15
  • 34. Example: FizzBuzz fizzbuzz(UpTo) -> lists:map(fun(Counter) -> if (Counter rem 15) =:= 0 -> fizzbuzz; (Counter rem 3) =:= 0 -> fizz; (Counter rem 5) =:= 0 -> buzz; true -> Counter end end, lists:seq(1, UpTo)). 1> examples:fizzbuzz(16). [1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16]
  • 35. Process: Concurrency • Any function (named or anonymous) can become a process • A process is simply a function executing in parallel • A process shares nothing with other processes • A process is extremely lightweight: a modern systems can accommodate literally millions of Erlang processes
  • 36. Process: Concurrency 1> processes:profileSpawnFor(1000). Spawned 1000 processes in 10 (4) milliseconds ok 2> processes:profileSpawnFor(10000). Spawned 10000 processes in 40 (96) milliseconds ok 3> processes:profileSpawnFor(100000). Spawned 100000 processes in 510 (884) milliseconds ok
  • 38. Process: Concurrency • The “!” operator sends messages • Asynchronous • Order guaranted • The “receive” statement matches messages • One call to receive, one message removed from the process message queue • Uses pattern matching to select messages
  • 39. Process: Concurrency 1> Pid = spawn(fun() -> 1> receive 1> die -> io:format(quot;Bye~nquot;) 1> end 1> end). <0.33.0>
  • 40. Process: Concurrency 2> is_process_alive(Pid). true 3> Pid ! die. Bye die 4> is_process_alive(Pid). false
  • 41. Process: Concurrency profileSpawnFor(Number) -> Processes = for(1, Number, fun() -> spawn(fun() -> wait() end) end), lists:foreach(fun(Pid) -> Pid ! die end, Processes). wait() -> receive die -> void end.
  • 42. Process: Fault Tollerance • The “link” function can link processes • When a process die the linked processes receive a message { ‘EXIT’, Died, Reason } • A monitor process could respawn the died ones or cleanup the system
  • 43. Process: Distributed • The spawn(Node, Function) can spawn a process in any other known nodes • No other changes are required!!!
  • 44. Hard Gained Insights • Don’t miss tail-call recursion • Asynchronous is good • Small functions are good • When in doubt create a new process • Think early what to do when a process die
  • 45.
  • 46. Disco (Map/Reduce with Erlang + Python) Yaws (Yet Another Web Server) eJabbered (jabber/XMPP)