Introduc)on to Erlang 
          Abd El‐Fa3ah Hussein Mahran 
Agenda
    History of Erlang
    Erlang Features
    Erlang/OTP and design patterns
    Tools applications
    Applic...
History of Erlang

    Erlang is a programming
     language
    Ericsson wanted
     programming language for
     deve...
History of Erlang
                                                               1998:
                       No language ...
Erlang is Concurrent functional
         programming language

It was designed by Ericsson to support distributed, fault-t...
Erlang Features
    Concurrency
    Fault tolerance
    Soft Real-Time
    Distribution
    Hot Code Loading
    Ext...
Erlang/OTP and design patterns

    Gen_Server Behaviour
    Gen_Fsm Behaviour
    Gen_Event Behaviour
    Supervisor ...
Tools applications
    Dialyzer
    Eunit
    Edoc
    Common_test
    Test_server
    Jinterface
    Erl_interface...
Applications written in Erlang
Applications written in Erlang
    Ericsson Company                                          Netkit Solutions (Network E...
Erlang IDEs
    Eclipse (ErlIDE plugin)
    NetBeans (ErlyBird)
    Emacs
    VIM
    Any other editor (Gedit, Notepa...
Erlang syntax
    Data types
    If statement
    Case statement
    Functions
    Modules
    Hello World program
...
Data types
    Number
        Integer 12, 43
        Float    34.3
    Atoms       create, remove
    Binaries <<“hel...
If statement
if
  GuardSeq1 ->
      Body1;
  ...;
  GuardSeqN ->
      BodyN
end.
Case Statement
case Expr of
  Pattern1 [when GuardSeq1]->
       Body1;
  ...;
  PatternN [when GuardSeqN] ->
       BodyN...
Functions
Clause 1     Name(Pattern11,...,Pattern1N) [when GuardSeq1] ->
                 Body1;
             ...;
Clause ...
Modules
-module(moduleName).

-export([func/0, func/1]).

func() ->
  foo(5),
  ….

func(A) ->
  foo(A),
  ….

foo(N) ->
 ...
Hello world Program
                                      Save the file as
                                  “hello_world....
How Erlang works
    Pattern matching technique
         Var = 3.
         [Var1, Var2] = [3, 4].
         {Var3, _Var...
Recursion and Tail Recursion


fact(0) ->            fact(N) ->
   1;                    fact_help(N, 1).
fact(N) when N>0...
Quick Sort
quicksort([]) -> % If the list [] is empty, return an empty list (nothing to sort)
   [];
quicksort([Pivot|Rest...
How to get Erlang
    Erlang.org
    Download
    Documentation
    Trapexit.org
    Erlang Factory
    Erlang-Consu...
Demo
    Hot Code swapping
    Concurrency
    Fault tolerance
    Distributed application
Hot Code swapping
-module(changing_code).

-export([start/0, loop/0]).
                                               % Fo...
Concurrency
portscan(Ip, From, To) when From < To ->
  io:format("Ports open for: ~p:~n", [Ip]),
  pforeach(fun(Port) -> s...
Fault tolerance
init([]) ->
    AChild=
    {main_module,{main_module, start_link, []}, permanent,
    2000, worker, [main...
Distributed application
                                Timeout to wait until
                                restart appl...
Conclusion
    Erlang is concurrent functional programming
     language.
    Its main goal is error recovery, fault tol...
References

    Erlang.org
    Trapexit.org
    Programming Erlang, Joe Armstong
    Wikipedia.com
Q&A
Thanks
Upcoming SlideShare
Loading in...5
×

Introduction To Erlang Final

4,072

Published on

Published in: Technology, News & Politics
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,072
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
143
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Introduction To Erlang Final

  1. 1. Introduc)on to Erlang            Abd El‐Fa3ah Hussein Mahran 
  2. 2. Agenda   History of Erlang   Erlang Features   Erlang/OTP and design patterns   Tools applications   Applications written in Erlang   Erlang IDEs   Erlang syntax   How to get Erlang   Demo   Conclusion   Q&A
  3. 3. History of Erlang   Erlang is a programming language   Ericsson wanted programming language for developing telecommunication switching systems.   The language must be a very high level symbolic language in order to achieve productivity gains   The language must contain primitives for concurrency and error recovery
  4. 4. History of Erlang 1998: No language well suited Open Source for telecom systems Erlang 1984: development Ericsson Computer Science Lab 1991: formed First fast implementation 1987: 1984-86: Early Erlang Experiments Prototype 1996: programming projects Open Telecom Platform POTS with (research on verification...)‫‏‬ several languages 1995: Several new projects 1993: Distributed Erlang
  5. 5. Erlang is Concurrent functional programming language It was designed by Ericsson to support distributed, fault-tolerant, soft-real-time, and non-stop applications
  6. 6. Erlang Features   Concurrency   Fault tolerance   Soft Real-Time   Distribution   Hot Code Loading   External Interfaces   Platform Independent
  7. 7. Erlang/OTP and design patterns   Gen_Server Behaviour   Gen_Fsm Behaviour   Gen_Event Behaviour   Supervisor Behaviour   Releases   Target systems
  8. 8. Tools applications   Dialyzer   Eunit   Edoc   Common_test   Test_server   Jinterface   Erl_interface Depending on   wx C++ WXwidgets   Ssh   Ssl   xmerl
  9. 9. Applications written in Erlang
  10. 10. Applications written in Erlang   Ericsson Company   Netkit Solutions (Network Equipment Monitoring and Operations Support Systems)   Bluetail/Alteon/Nortel (distributed, fault tolerant email system, SSL accelerator)   Process-one (Jabber Messaging)   Cellpoint (Location-based Mobile Services)   Schlund + Partner (Messaging and Interactive Voice Response services)   Corelatus (SS7 monitoring).   Quviq (Software Test Tool)   dqdp.net (in Latvian) (Web Services).   RabbitMQ (AMQP Enterprise Messaging)   Facebook (Facebook chat backend)   T-Mobile (previously one2one) (advanced call   Finnish Meteorological Institute (Data acquisition control services) and real-time monitoring)   Telia (a telecomms operator)   IDT corp. (Real-time least-cost routing expert systems)   Vail Systems (Interactive Voice Response systems)   Kreditor (Electronic payment systems)   Wavenet (SS7 and IVR applications)   Mobilearts (GSM and UMTS services)
  11. 11. Erlang IDEs   Eclipse (ErlIDE plugin)   NetBeans (ErlyBird)   Emacs   VIM   Any other editor (Gedit, Notepad++)
  12. 12. Erlang syntax   Data types   If statement   Case statement   Functions   Modules   Hello World program   How Erlang works
  13. 13. Data types   Number   Integer 12, 43   Float 34.3   Atoms create, remove   Binaries <<“hello”>> Erlang don’t have   Reference boolean as data   Fun type, instead Erlang   Port Identifier has true and false   Pid <0,36,0>   Tuple {1, 2, 3}   List [1, 2, 3, 4]   String “hello”   Record -record(person, {name, age, phone}).
  14. 14. If statement if GuardSeq1 -> Body1; ...; GuardSeqN -> BodyN end.
  15. 15. Case Statement case Expr of Pattern1 [when GuardSeq1]-> Body1; ...; PatternN [when GuardSeqN] -> BodyN end.
  16. 16. Functions Clause 1 Name(Pattern11,...,Pattern1N) [when GuardSeq1] -> Body1; ...; Clause 2 Name(PatternK1,...,PatternKN) [when GuardSeqK] -> ….., BodyK. Parameters Conditions Function name Body
  17. 17. Modules -module(moduleName). -export([func/0, func/1]). func() -> foo(5), …. func(A) -> foo(A), …. foo(N) -> …, …, ...
  18. 18. Hello world Program Save the file as “hello_world.erl”, After -module(hello_world). compilation output will be “hello_world.beam” -export([print/0]). $ erl Eshell V 5.7.1 (abort with ^G) print() -> 1> c(hello_world). {ok, hello_world} io:format(“Hello World…!~n”). 2> hello_world:print(). Hello World…! 3>
  19. 19. How Erlang works   Pattern matching technique   Var = 3.   [Var1, Var2] = [3, 4].   {Var3, _Var4, Var5} = {4, 5, a}.   [H | T] = [iti, erlang, course, book]. 1 = 1. {ok, Var} = {ok, “Connected to DB”}. √ 1 = 2. {ok, var} = {ok, “Connected to DB”}. X
  20. 20. Recursion and Tail Recursion fact(0) -> fact(N) -> 1; fact_help(N, 1). fact(N) when N>0 -> N * fact(N -1). fact_help(0, Acc) -> Acc; fact_help(N, Acc) when N>0 -> NewAcc = N * Acc, fact_help(N-1, NewAcc).
  21. 21. Quick Sort quicksort([]) -> % If the list [] is empty, return an empty list (nothing to sort) []; quicksort([Pivot|Rest]) -> quicksort([Front || Front <- Rest, Front < Pivot]) ++ [Pivot] ++ quicksort([Back || Back <- Rest, Back >= Pivot]).
  22. 22. How to get Erlang   Erlang.org   Download   Documentation   Trapexit.org   Erlang Factory   Erlang-Consulting
  23. 23. Demo   Hot Code swapping   Concurrency   Fault tolerance   Distributed application
  24. 24. Hot Code swapping -module(changing_code). -export([start/0, loop/0]). % Forces the use of start() -> loop/0 from spawn(changing_code, loop, []). the latest version of loop() -> changing_code receive switch -> changing_code:loop(); hello -> io:format(“CAT Hackers ----1~n”), loop(); Msg -> io:format(“~p~n”, [Msg]), loop(), end.
  25. 25. Concurrency portscan(Ip, From, To) when From < To -> io:format("Ports open for: ~p:~n", [Ip]), pforeach(fun(Port) -> scan(Ip,Port) end,lists:seq(From, To)). scan(Ip, Port) -> case gen_tcp:connect(Ip,Port,[{active, false}, binary]) of {ok,P} -> gen_tcp:close(P), io:format("~p is open~n", [Port]); _ -> ok end. pforeach(F, [H|T]) -> spawn(fun() -> F(H) end), pforeach(F, T); pforeach(_ , []) -> ok.
  26. 26. Fault tolerance init([]) -> AChild= {main_module,{main_module, start_link, []}, permanent, 2000, worker, [main_module]}, {ok,{{one_for_one, 1, 60}, [AChild]}}.
  27. 27. Distributed application Timeout to wait until restart application on Nodes other node [{kernel, [{distributed, [{dist_app, 5000, [‘node1@ricsson.com’, {‘node2@ricsson.com’, ‘node3@ricsson.com’}]}]}, {sync_nodes_mandatory, [‘node2@ricsson.com’, ‘node3@ricsson.com’]}, {sync_nodes_timeout, 5000} ] } ]. Specifies how many milliseconds to wait for the other nodes to start
  28. 28. Conclusion   Erlang is concurrent functional programming language.   Its main goal is error recovery, fault tolerant, distributed applications, and non-stop applications.   It released to Open source since 1998.   Companies that are using Erlang.   How Erlang works.   How to get and use Erlang.
  29. 29. References   Erlang.org   Trapexit.org   Programming Erlang, Joe Armstong   Wikipedia.com
  30. 30. Q&A
  31. 31. Thanks
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×