Prolog	
  to	
  Erlang	
  

First	
  version	
  of	
  Erlang	
  was	
  wri2en	
  in	
  
                       Prolog	
  
Examples	
  
hello_mod.erl	
  
1.  -­‐module(hello_mod).	
  
2.  -­‐export([say_hello/0]).	
  

3.  say_hello()	
  -­‐>	
  
4.  	
  	
  	
  	
  io:format("Hello~n",	
  []).	
  
hello_mod:say_hello().	
  
1.  $	
  erl	
  
2.  Erlang	
  R14B04	
  (erts-­‐5.8.5)	
  [source]	
  [64-­‐bit]	
  [smp:4:4]	
  
    [rq:4]	
  [async-­‐threads:0]	
  [hipe]	
  [kernel-­‐poll:false]	
  

3.    Eshell	
  V5.8.5	
  	
  (abort	
  with	
  ^G)	
  
4.    1>	
  c(hello_mod).	
  
5.    {ok,hello_mod}	
  
6.    2>	
  hello_mod:say_hello().	
  
7.    Hello	
  
8.    ok	
  
9.    3>	
  	
  
fact_mod.erl	
  
1.  -­‐module(fact_mod).	
  
2.  -­‐export([fact/1]).	
  

3.  fact(0)	
  -­‐>	
  1;	
  
4.  fact(N)	
  -­‐>	
  N	
  *	
  fact(N	
  -­‐	
  1).	
  
fact_mod:fact(4).	
  
1.  $	
  erl	
  
2.  Erlang	
  R14B04	
  (erts-­‐5.8.5)	
  [source]	
  [64-­‐bit]	
  [smp:4:4]	
  
    [rq:4]	
  [async-­‐threads:0]	
  [hipe]	
  [kernel-­‐poll:false]	
  

3.    Eshell	
  V5.8.5	
  	
  (abort	
  with	
  ^G)	
  
4.    1>	
  c(fact_mod).	
  
5.    {ok,fact_mod}	
  
6.    2>	
  fact_mod:fact(4).	
  
7.    24	
  
8.    3>	
  	
  
qsort_mod.erl	
  
1.  -­‐module(qsort_mod).	
  
2.  -­‐export([qsort/1]).	
  

3.    qsort([])	
  -­‐>	
  
4.    	
  	
  	
  	
  [];	
  
5.    qsort([H	
  |	
  T])	
  -­‐>	
  	
  
6.    	
  	
  	
  	
  qsort([	
  X	
  ||	
  X	
  <-­‐	
  T,	
  X	
  <	
  H	
  ])	
  ++	
  	
  
7.              	
   [H]	
  ++	
  	
  
8.              	
   qsort([	
  X	
  ||	
  X	
  <-­‐	
  T,	
  X	
  >=	
  H	
  ]).	
  
qsort_mod:qsort([3,	
  2,	
  1,	
  6,	
  4,	
  5]).	
  
                      	
  
1.  $	
  erl	
  
2.  Erlang	
  R14B04	
  (erts-­‐5.8.5)	
  [source]	
  [64-­‐bit]	
  [smp:4:4]	
  
    [rq:4]	
  [async-­‐threads:0]	
  [hipe]	
  [kernel-­‐poll:false]	
  

3.    Eshell	
  V5.8.5	
  	
  (abort	
  with	
  ^G)	
  
4.    1>	
  c(qsort_mod).	
  
5.    {ok,qsort_mod}	
  
6.    2>	
  qsort:qsort([3,	
  2,	
  1,	
  6,	
  4,	
  5]).	
  
7.    [1,2,3,4,5,6]	
  
8.    3>	
  	
  
History	
  
§  1986	
  -­‐	
  Joe	
  Armstong	
  (Ericsson)	
  
   §  Prolog	
  
§  1988	
  -­‐	
  Ericsson	
  AXD301	
  ATM	
  telco	
  switch	
  
   §  1	
  million	
  lines	
  of	
  Erlang	
  
   §  99.9999999	
  
§  1995	
  -­‐	
  Open	
  Telecom	
  Plalorm	
  
§  1998	
  -­‐	
  Open	
  source	
  
§  2011	
  -­‐	
  Release	
  14B03	
  
What s	
  Erlang?	
  
Programming	
  Language	
  
§  General-­‐purpose	
  
§  Funcponal	
  	
  
   §  Like	
  LISP,	
  Haskell	
  
§  Garbage-­‐collected	
  
§  Dynamic	
  typing	
  
§  Single	
  assignment	
  
§  Erlang	
  runpme	
  system	
  
   §  STDLIB	
  
Features	
  
§  Massive	
  concurrency	
  and	
  message	
  passing	
  
     §    Actor	
  model	
  
     §    Sos-­‐real-­‐pme	
  
     §    Thousands	
  of	
  processes	
  under	
  single	
  VM	
  
     §    Short	
  GC	
  pauses	
  
§  Distributed	
  
     §  Erlang	
  nodes	
  
§  Fault-­‐tolerant	
  
     §  99.9999999%	
  
§  Powerful	
  error	
  handling	
  
     §  Supervisors	
  
     §  Recovery	
  from	
  errors	
  
§  Non-­‐stop	
  systems	
  
     §  Hot	
  code	
  swapping	
  in	
  producpon	
  
Data	
  types	
  
§  Atoms	
  
     §  open,	
  close,	
  `empty	
  
§  Integers	
  
§  Floats	
  
§  Tuples	
  
     §  {price,	
  12.34}	
  
§  Lists	
  
     §  [1,	
  2,	
  3,	
  4]	
  
§  PIDs	
  
Control	
  Structures	
  
§  Pa2ern	
  matching	
  
§  Guards	
  
§  Higher	
  order	
  funcpons	
  
§  List	
  comprehension	
  
Actors:Message	
  Passing	
  
§  Send	
  message	
  (client	
  process)	
  
   §  ServerProcessId	
  !	
  Message.	
  
§  Receiving	
  a	
  message	
  (server	
  process)	
  
   §  receive	
  
        	
  pa2ern2	
  -­‐>	
  …;	
  
        	
  pa2ern2	
  -­‐>	
  …	
  
       end.	
  
Erlang	
  VM	
  
§  Thousands	
  of	
  processes	
  under	
  single	
  VM	
  
§  Lightweight	
  processes	
  
§  Garbage	
  collecpon	
  per	
  process	
  
§  BEAM	
  files	
  
§  Napve	
  code	
  compiler	
  
Anywhere	
  
§  OS	
  /	
  Hardware	
  independent	
  
   §  UNIX/Linux	
  
   §  Windows	
  
   §  Mac	
  
   §  Embedded	
  
   §  Android	
  
Open	
  Telecom	
  Plalorm	
  

            OTP	
  
OTP	
  Design	
  Principles	
  
§  Supervision	
  trees	
  
    §  Supervisors	
  
    §  Workers	
  
§  Behaviours	
  
    §  gen_server	
  
         §  The	
  server	
  in	
  client-­‐server	
  
    §  fsm_server	
  
         §  Finite	
  state	
  machines	
  
    §  gen_event	
  
         §  Event	
  handling	
  
§  Applicapons	
  
    §  Applicapon	
  
§  Releases	
  
Web	
  Development	
  
Web	
  Development	
  
§  Web	
  Servers	
  
     §  Inets	
  
            §  Build-­‐in	
  
     §  Yaws	
  
            §  80,000	
  concurrent	
  connecpons	
  (2002)	
  
     §  MochiWeb	
  
            §  Lightweight	
  HTTP	
  
§  Web	
  Frameworks	
  
     §  ErlyWeb	
  
            §  MVC	
  for	
  Yaws	
  
     §  Erlang	
  Web	
  
            §  MVC	
  for	
  Yaws	
  and	
  Inets	
  
     §  Nitrogen	
  
            §  An	
  event-­‐driven	
  2.0	
  framework	
  (cometd)	
  
Wri2en	
  in	
  Erlang	
  
§  Apache	
  CouchDB	
  
    §  Document-­‐oriented	
  database	
  (replicapon)	
  
§  RabbitMQ	
  
    §  Message-­‐oriented	
  middleware	
  
§  Riak	
  
    §  NoSQL	
  database	
  (ring)	
  
§  Ejabberd	
  
    §  XMPP	
  applicapon	
  server	
  
Development	
  Tools	
  
§  IDEs	
  
    §  Eclipse	
  
    §  Emacs	
  +	
  Distel	
  
    §  Vim	
  
§  Tools	
  
    §  MOEBIUS	
  
         §  CI	
  Server	
  
    §  rebar	
  
         §  Build	
  and	
  packaging	
  tool	
  
Erlang	
  in	
  Producpon	
  
§  Ericsson	
  AXD301	
  telco	
  switch	
  
     §    160	
  GB/s	
  
     §    1	
  million	
  lines	
  of	
  Erlang	
  
     §    Hundreds	
  of	
  programmers	
  
     §    99.9	
  999	
  999%	
  reliability	
  
§  GPRS	
  
     §  GSM	
  cell	
  telco	
  network	
  
§  Facebook	
  Chat	
  
     §  800+	
  million	
  messages	
  /	
  day	
  
§  GitHub	
  
§  Goldman	
  Sachs	
  ???	
  
     §  High-­‐frequency	
  trading	
  
§  Deutsche	
  Bank	
  

Erlang Lightning Talk

  • 1.
    Prolog  to  Erlang   First  version  of  Erlang  was  wri2en  in   Prolog  
  • 2.
  • 3.
    hello_mod.erl   1.  -­‐module(hello_mod).   2.  -­‐export([say_hello/0]).   3.  say_hello()  -­‐>   4.         io:format("Hello~n",  []).  
  • 4.
    hello_mod:say_hello().   1.  $  erl   2.  Erlang  R14B04  (erts-­‐5.8.5)  [source]  [64-­‐bit]  [smp:4:4]   [rq:4]  [async-­‐threads:0]  [hipe]  [kernel-­‐poll:false]   3.  Eshell  V5.8.5    (abort  with  ^G)   4.  1>  c(hello_mod).   5.  {ok,hello_mod}   6.  2>  hello_mod:say_hello().   7.  Hello   8.  ok   9.  3>    
  • 5.
    fact_mod.erl   1.  -­‐module(fact_mod).   2.  -­‐export([fact/1]).   3.  fact(0)  -­‐>  1;   4.  fact(N)  -­‐>  N  *  fact(N  -­‐  1).  
  • 6.
    fact_mod:fact(4).   1.  $  erl   2.  Erlang  R14B04  (erts-­‐5.8.5)  [source]  [64-­‐bit]  [smp:4:4]   [rq:4]  [async-­‐threads:0]  [hipe]  [kernel-­‐poll:false]   3.  Eshell  V5.8.5    (abort  with  ^G)   4.  1>  c(fact_mod).   5.  {ok,fact_mod}   6.  2>  fact_mod:fact(4).   7.  24   8.  3>    
  • 7.
    qsort_mod.erl   1.  -­‐module(qsort_mod).   2.  -­‐export([qsort/1]).   3.  qsort([])  -­‐>   4.         [];   5.  qsort([H  |  T])  -­‐>     6.         qsort([  X  ||  X  <-­‐  T,  X  <  H  ])  ++     7.    [H]  ++     8.    qsort([  X  ||  X  <-­‐  T,  X  >=  H  ]).  
  • 8.
    qsort_mod:qsort([3,  2,  1,  6,  4,  5]).     1.  $  erl   2.  Erlang  R14B04  (erts-­‐5.8.5)  [source]  [64-­‐bit]  [smp:4:4]   [rq:4]  [async-­‐threads:0]  [hipe]  [kernel-­‐poll:false]   3.  Eshell  V5.8.5    (abort  with  ^G)   4.  1>  c(qsort_mod).   5.  {ok,qsort_mod}   6.  2>  qsort:qsort([3,  2,  1,  6,  4,  5]).   7.  [1,2,3,4,5,6]   8.  3>    
  • 9.
    History   §  1986  -­‐  Joe  Armstong  (Ericsson)   §  Prolog   §  1988  -­‐  Ericsson  AXD301  ATM  telco  switch   §  1  million  lines  of  Erlang   §  99.9999999   §  1995  -­‐  Open  Telecom  Plalorm   §  1998  -­‐  Open  source   §  2011  -­‐  Release  14B03  
  • 10.
  • 11.
    Programming  Language   § General-­‐purpose   §  Funcponal     §  Like  LISP,  Haskell   §  Garbage-­‐collected   §  Dynamic  typing   §  Single  assignment   §  Erlang  runpme  system   §  STDLIB  
  • 12.
    Features   §  Massive  concurrency  and  message  passing   §  Actor  model   §  Sos-­‐real-­‐pme   §  Thousands  of  processes  under  single  VM   §  Short  GC  pauses   §  Distributed   §  Erlang  nodes   §  Fault-­‐tolerant   §  99.9999999%   §  Powerful  error  handling   §  Supervisors   §  Recovery  from  errors   §  Non-­‐stop  systems   §  Hot  code  swapping  in  producpon  
  • 13.
    Data  types   § Atoms   §  open,  close,  `empty   §  Integers   §  Floats   §  Tuples   §  {price,  12.34}   §  Lists   §  [1,  2,  3,  4]   §  PIDs  
  • 14.
    Control  Structures   § Pa2ern  matching   §  Guards   §  Higher  order  funcpons   §  List  comprehension  
  • 15.
    Actors:Message  Passing   § Send  message  (client  process)   §  ServerProcessId  !  Message.   §  Receiving  a  message  (server  process)   §  receive    pa2ern2  -­‐>  …;    pa2ern2  -­‐>  …   end.  
  • 16.
    Erlang  VM   § Thousands  of  processes  under  single  VM   §  Lightweight  processes   §  Garbage  collecpon  per  process   §  BEAM  files   §  Napve  code  compiler  
  • 17.
    Anywhere   §  OS  /  Hardware  independent   §  UNIX/Linux   §  Windows   §  Mac   §  Embedded   §  Android  
  • 18.
  • 19.
    OTP  Design  Principles   §  Supervision  trees   §  Supervisors   §  Workers   §  Behaviours   §  gen_server   §  The  server  in  client-­‐server   §  fsm_server   §  Finite  state  machines   §  gen_event   §  Event  handling   §  Applicapons   §  Applicapon   §  Releases  
  • 20.
  • 21.
    Web  Development   § Web  Servers   §  Inets   §  Build-­‐in   §  Yaws   §  80,000  concurrent  connecpons  (2002)   §  MochiWeb   §  Lightweight  HTTP   §  Web  Frameworks   §  ErlyWeb   §  MVC  for  Yaws   §  Erlang  Web   §  MVC  for  Yaws  and  Inets   §  Nitrogen   §  An  event-­‐driven  2.0  framework  (cometd)  
  • 22.
    Wri2en  in  Erlang   §  Apache  CouchDB   §  Document-­‐oriented  database  (replicapon)   §  RabbitMQ   §  Message-­‐oriented  middleware   §  Riak   §  NoSQL  database  (ring)   §  Ejabberd   §  XMPP  applicapon  server  
  • 23.
    Development  Tools   § IDEs   §  Eclipse   §  Emacs  +  Distel   §  Vim   §  Tools   §  MOEBIUS   §  CI  Server   §  rebar   §  Build  and  packaging  tool  
  • 24.
    Erlang  in  Producpon   §  Ericsson  AXD301  telco  switch   §  160  GB/s   §  1  million  lines  of  Erlang   §  Hundreds  of  programmers   §  99.9  999  999%  reliability   §  GPRS   §  GSM  cell  telco  network   §  Facebook  Chat   §  800+  million  messages  /  day   §  GitHub   §  Goldman  Sachs  ???   §  High-­‐frequency  trading   §  Deutsche  Bank