SlideShare a Scribd company logo
Three sessions about Erlang




         Session 1
       Mohamed Samy
       February 2010
The need for parallel processing

  
      It has become prohibitive to raise the clock
      speeds of current CPUs any further.
  
      The next trend is to increase the number of CPU
      cores.
  
      In order to benefit from CPU upgrades, programs
      need to make the maximum possible use of
      parallelism.
  
      “The free lunch is over“
      (http://www.gotw.ca/publications/concurrency-
      ddj.htm)
Also, distributed processing :)

  
      Not only is the program running on multiple
      CPUs, but on multiple computers over the
      network.
  
      No shared memory, communication by
      message passing.
  
      Google's index, for example.
Current languages

 
     Both parallel and distributed applications have
     been written in traditional languages like C++,
     Java or C#, but...
 
     The problem is these languages depend too
     much on shared state.
 
     And they inherently make you think sequentially.
 
     Your programming language influences how you
     think about programs, not just how you write
     code.
Current languages
 
     The problem of shared mutable state (e.g
     global variables, object references...)
 
     Loop iterations run in sequence
 
     Assignment is very sequential
 Function calls have problems
     
         e.g: If function a( ) calls b( ), it keeps waiting for b( )
         to return before resuming operation.
 
     ‫فيه طرق للبرمجة غير كده أصل ؟‬
Erlang
 
     Created in 1986 by Joe Armstrong at Ericsson.
 
     Functional, dynamically typed, uses the actor
     model.
 
     Design goals:
     
         Concurrency, distribution, robustness, "soft" real
         time, hot code upgrades...and other goals.
 
     Used in Ericsson devices, Facebook chat,
     Amazon SimpleDB, now quickly growing.
 
     Now open source
Contents

 
     1st session: Sequential Erlang.

 
     2nd session: Concurrency and Actors.

 
     3rd session: A simple web application
Objectives of these sessions
  
      Introducing new concepts (Actor model,
      functional programming, immutable data).
  
      The importance of parallel programming.
  
      Stressing that there is much more to know
      about programming outside of traditional
      languages like C++, Java or C#.
      
          Not necessarily from Erlang only.
Erlang resources
 
     Download from
     http://www.erlang.org/download.html
 
     Lots and lots of documentation are included!
     
         Located in c:Program fileserl5.7.4docindex.html
     
         Especially look at "Getting started with
         Erlang" and "Erlang reference manual"
 
     Nice, searchable version of the
     documentation at www.erldocs.com
The Environment
    Commands always end in a dot: .
    help( ) to show all options
    cd(path) to change working directory
     Paths use a forward slash: "c:/examples/test1"
    c(file) to load & compile a file.
     e.g: c("example1"). % .erl extension is optional
    f( ) to forget all variable bindings
    Simple autocomplete with the <TAB> key.
    Lots and lots of documentation are included!
        c:Program fileserl5.7.4docindex.html
    Nice, searchable version of the documentation at www.erldocs.com
Data types
    Numbers: 12, -100, 15.55, $a
    Atoms: x, ayman, faculty_of_law
        Simple atoms cannot begin with a capital letter or have spaces,
         but single quotes can be used to bypass those rules: 'Samy',
         'calculus book'
    Tuples: { samy, 1979, cairo }, {13, 28}
    Lists: [ ], [1, 2, 3], [a, [b, c], {1, 2} ]
    Strings: "Hello world"
        This actually is the list [$H, $e, $l, $l, $o, $ ,$w, $o, $r, $l, $d ]
    All these data types are immutable
Data types and variables
 
     More information about these data types in the Erlang
     reference.
    Other important data types exists (e.g PID).
 
     A piece of data of any data type is called a term.
    Variables always start with a capital letter or underscore:
     X, Y, _Name, _name
 
     Variables can be bound to a value or still unbound
 
     Erlang has single assignment: a variable cannot be
     bound more than once.
Pattern matching
    A pattern is a term which may contain one or more variables.
    A term with no variables at all can be considered a pattern.
    Matching syntax is:
        Pattern = Term
    Each respective component of the term is compared,
     matching attempts to find the most general variable binding to
     make the match succeed.
    Quiz: what is the result of the following matches?
Pattern matching
 
     5=5.


 
     {Name, Age, _} = {“Osama”, 28, cairo }.


 
     [1,2] = {1, 2}.


 
     "hello" = "hello".


 
     "ABC" = [65, 66, 67].


    $a = a.
More pattern matching quizzes
 
     X=5.


 
     X=5. Y=X+1. Y=3+3.


 
     X=Y. Y=1.


 
     { X, Y } = { 5, 6 }


 
     { Y, Y } = { 5, 6 }


 (When testing these on Erlang; remember to use f( ) to reset
   variable bindings.)
Pattern matching on lists
  
      [ H | T ] = [1, 2, 3].
  
      [ H | T ] = [ ].
  
      [ H | T ] = [1, 2].
  
      [ H1, H2 | T ] = [1, 2, 3].
  
      [ H1, H2 | T ] = [1, 2].
  
      [A, B] ++ [ H| T] = "faculty".
  
      "Mustafa" ++ X = "Mustafa Kamel".
Some simple I/O
io:format(fmt_str, [arg0,arg1... ])

    Examples:
    
        io:format("The results are ~p and ~p", [15, 16]).
    
        io:format("Hello world ~n", [ ]).
    
        io:format("Hello world ~n").

    Codes:
    
        ~~ : The '~' mark (needs no argument)
    
        ~f : Format argument as floating point
    
        ~c : Format argument as a character.
    
        ~w : Format argument in standard syntax (i.e like terms in the language)
    
        ~p : Standard syntax for printing (e.g turns lists of printable characters into strings)
    
        ~n : newline character (doesn't need an argument).

    Much more detail in the documentation. Erlang has very rich formatting
    features.
More simple I/O
io:get_line(Prompt) -> Data | eof | {error,Reason}
     
         Gets a line from standard input as a string (includes the newline character).
io:read(Prompt) → {ok, Term} | eof | {error, ErrorInfo}
     
         Reads a term from standard input (user must include ending period).
io:fread(Prompt, Format) -> {ok, Terms} | eof | {error, What}
     
         Reads characters and returns a list of terms, parsed according to the specified format
         specification (different from that of io:format).

    Examples:
     
         io:read("Enter a point>").
     Enter a point>{13, 14}.
     {ok, {13, 14}}
     
         io:get_line("Enter your name>").
     Enter your name>Captain Majid
     “Captain Majidn"

    io:format( ), io:read( ) and all the other given i/o functions have additional parameters that can
    make them read from I/O devices like files...etc
Modules

          -module(addition).
          -export([add/2, add/3]).

          add(X, Y) -> X+Y.
          add(X, Y, Z) -> X+Y+Z.
          unused_func( ) -> io:format("unused!").
          % End of module definition.


    Erlang code is divided into modules.
 
     A module has attributes at the top (the begin with the dash character '-') and is followed by
     function declarations. Both attributes and declaration end with a dot '.'
 
     Exported function names must include its artiy (number of parameters).
 
     Two functions with the same name but different arities are different functions!
Functions
 
     add(A, B) → A+B.
        −   Return value is the function's expression
 
     add(A, B) →
     io:format(“now adding ~p and ~p~n", [A, B]),
     A+B.
        −   In case of multiple expressions, return value is the last
            one
Functions
 
     absolute(A) when A>0 → 1
     ;
 absolute(A) when A=0 → 0
     ;
 absolute(A) → -1
     .
 
     The expressions after when are called guard
     sequences. More about them in the Erlang language
     reference → Expressions → Guard sequences
Pattern matching in functions
  
      distance({X1 Y1}, {X2, Y2}) →
  Dx= X1-X2,
  Dy= Y1-Y2,
  math:sqrt(Dx*Dx + Dy*Dy).
  
      Tuples can be confusing (e.g is a tuple of two
      numbers a point, vector or age & salary?).
  
      We can use an atom in the beginning (the tag)
      to distinguish between kinds of data...
Pattern matching in functions
  
      distance({point, X1, Y1}, {point, X2, Y2}) →
  Dx= X1-X2,
  Dy= Y1-Y2,
  math:sqrt(Dx*Dx + Dy*Dy).

  
      example:distance({point, 0, 0}, {point, 100,
      100}).
Recursion
 factorial(0) ->1 ;
 factorial(N) -> N*factorial(N-1).

 
     Function calls, activation records, and why this
     works.
 
     We need this; we don't have loops !
 
     The space requirements of naïve recursion.
Recursion
 
     Tail calls vs. non tail calls.
 
     Tails calls are not only about recursion, but any
     function call.
 
     Tail call elimination. Now recursion can be as
     good as loops.
 
     In fact, it's can be compiled to jump instructions.
 
     Sometimes it can be much better than loops!
     
         Example: state machines
Next...

  
      Processes!
  
      Actors!
  
      Ping pong!
         −   Thursday, 11 February 2010.

More Related Content

What's hot

Data Handling
Data HandlingData Handling
Data Handling
Praveen M Jigajinni
 
Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
Patrick Huesler
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in Java
Rasan Samarasinghe
 
Chapter 10 data handling
Chapter 10 data handlingChapter 10 data handling
Chapter 10 data handling
Praveen M Jigajinni
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
hishamrizvi
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
Akhil Kaushik
 
Regular Expressions in PHP
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHP
Andrew Kandels
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
Raghu Kumar
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Python basics
Python basicsPython basics
Python basics
Manisha Gholve
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
Atul Sehdev
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
Jothi Thilaga P
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform ResearchVasil Remeniuk
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad
 
Python programming
Python programmingPython programming
Python programming
saroja20
 
Data file handling
Data file handlingData file handling
Data file handling
Prof. Dr. K. Adisesha
 

What's hot (20)

Data Handling
Data HandlingData Handling
Data Handling
 
Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in Java
 
Chapter 10 data handling
Chapter 10 data handlingChapter 10 data handling
Chapter 10 data handling
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
 
3.5
3.53.5
3.5
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular Expressions in PHP
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHP
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Python basics
Python basicsPython basics
Python basics
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
 
Python lecture 06
Python lecture 06Python lecture 06
Python lecture 06
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform Research
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Python programming
Python programmingPython programming
Python programming
 
Data file handling
Data file handlingData file handling
Data file handling
 

Viewers also liked

C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3
mohamedsamyali
 
Erlang session2
Erlang session2Erlang session2
Erlang session2
mohamedsamyali
 
Presentation skills for Graduation projects
Presentation skills for Graduation projectsPresentation skills for Graduation projects
Presentation skills for Graduation projects
mohamedsamyali
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
mohamedsamyali
 
Computational thinking in Egypt
Computational thinking in EgyptComputational thinking in Egypt
Computational thinking in Egypt
mohamedsamyali
 
Smalltalk, the dynamic language
Smalltalk, the dynamic languageSmalltalk, the dynamic language
Smalltalk, the dynamic language
mohamedsamyali
 
Themes for graduation projects 2010
Themes for graduation projects   2010Themes for graduation projects   2010
Themes for graduation projects 2010
mohamedsamyali
 

Viewers also liked (8)

C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3
 
Spray intro
Spray introSpray intro
Spray intro
 
Erlang session2
Erlang session2Erlang session2
Erlang session2
 
Presentation skills for Graduation projects
Presentation skills for Graduation projectsPresentation skills for Graduation projects
Presentation skills for Graduation projects
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
 
Computational thinking in Egypt
Computational thinking in EgyptComputational thinking in Egypt
Computational thinking in Egypt
 
Smalltalk, the dynamic language
Smalltalk, the dynamic languageSmalltalk, the dynamic language
Smalltalk, the dynamic language
 
Themes for graduation projects 2010
Themes for graduation projects   2010Themes for graduation projects   2010
Themes for graduation projects 2010
 

Similar to Erlang session1

C# programming
C# programming C# programming
C# programming
umesh patil
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Hamidreza Soleimani
 
Introduction to Erlang Part 1
Introduction to Erlang Part 1Introduction to Erlang Part 1
Introduction to Erlang Part 1
Dmitry Zinoviev
 
Introduction to Python , Overview
Introduction to Python , OverviewIntroduction to Python , Overview
Introduction to Python , Overview
NB Veeresh
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Winl xf
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
rik0
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
PyCon Italia
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
Elixir
ElixirElixir
Elixir
Robert Brown
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
C++primer
C++primerC++primer
C++primer
leonlongli
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
Syed Zaid Irshad
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersSkills Matter
 

Similar to Erlang session1 (20)

C Tutorials
C TutorialsC Tutorials
C Tutorials
 
C# programming
C# programming C# programming
C# programming
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
Architecting Scalable Platforms in Erlang/OTP | Hamidreza Soleimani | Diginex...
 
Introduction to Erlang Part 1
Introduction to Erlang Part 1Introduction to Erlang Part 1
Introduction to Erlang Part 1
 
Introduction to Python , Overview
Introduction to Python , OverviewIntroduction to Python , Overview
Introduction to Python , Overview
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Win
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
Elixir
ElixirElixir
Elixir
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C++primer
C++primerC++primer
C++primer
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
Java
JavaJava
Java
 

Recently uploaded

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 

Erlang session1

  • 1. Three sessions about Erlang Session 1 Mohamed Samy February 2010
  • 2. The need for parallel processing  It has become prohibitive to raise the clock speeds of current CPUs any further.  The next trend is to increase the number of CPU cores.  In order to benefit from CPU upgrades, programs need to make the maximum possible use of parallelism.  “The free lunch is over“ (http://www.gotw.ca/publications/concurrency- ddj.htm)
  • 3. Also, distributed processing :)  Not only is the program running on multiple CPUs, but on multiple computers over the network.  No shared memory, communication by message passing.  Google's index, for example.
  • 4. Current languages  Both parallel and distributed applications have been written in traditional languages like C++, Java or C#, but...  The problem is these languages depend too much on shared state.  And they inherently make you think sequentially.  Your programming language influences how you think about programs, not just how you write code.
  • 5. Current languages  The problem of shared mutable state (e.g global variables, object references...)  Loop iterations run in sequence  Assignment is very sequential Function calls have problems  e.g: If function a( ) calls b( ), it keeps waiting for b( ) to return before resuming operation.  ‫فيه طرق للبرمجة غير كده أصل ؟‬
  • 6. Erlang  Created in 1986 by Joe Armstrong at Ericsson.  Functional, dynamically typed, uses the actor model.  Design goals:  Concurrency, distribution, robustness, "soft" real time, hot code upgrades...and other goals.  Used in Ericsson devices, Facebook chat, Amazon SimpleDB, now quickly growing.  Now open source
  • 7. Contents  1st session: Sequential Erlang.  2nd session: Concurrency and Actors.  3rd session: A simple web application
  • 8. Objectives of these sessions  Introducing new concepts (Actor model, functional programming, immutable data).  The importance of parallel programming.  Stressing that there is much more to know about programming outside of traditional languages like C++, Java or C#.  Not necessarily from Erlang only.
  • 9. Erlang resources  Download from http://www.erlang.org/download.html  Lots and lots of documentation are included!  Located in c:Program fileserl5.7.4docindex.html  Especially look at "Getting started with Erlang" and "Erlang reference manual"  Nice, searchable version of the documentation at www.erldocs.com
  • 10. The Environment  Commands always end in a dot: .  help( ) to show all options  cd(path) to change working directory Paths use a forward slash: "c:/examples/test1"  c(file) to load & compile a file. e.g: c("example1"). % .erl extension is optional  f( ) to forget all variable bindings  Simple autocomplete with the <TAB> key.  Lots and lots of documentation are included!  c:Program fileserl5.7.4docindex.html  Nice, searchable version of the documentation at www.erldocs.com
  • 11. Data types  Numbers: 12, -100, 15.55, $a  Atoms: x, ayman, faculty_of_law  Simple atoms cannot begin with a capital letter or have spaces, but single quotes can be used to bypass those rules: 'Samy', 'calculus book'  Tuples: { samy, 1979, cairo }, {13, 28}  Lists: [ ], [1, 2, 3], [a, [b, c], {1, 2} ]  Strings: "Hello world"  This actually is the list [$H, $e, $l, $l, $o, $ ,$w, $o, $r, $l, $d ]  All these data types are immutable
  • 12. Data types and variables  More information about these data types in the Erlang reference.  Other important data types exists (e.g PID).  A piece of data of any data type is called a term.  Variables always start with a capital letter or underscore: X, Y, _Name, _name  Variables can be bound to a value or still unbound  Erlang has single assignment: a variable cannot be bound more than once.
  • 13. Pattern matching  A pattern is a term which may contain one or more variables.  A term with no variables at all can be considered a pattern.  Matching syntax is:  Pattern = Term  Each respective component of the term is compared, matching attempts to find the most general variable binding to make the match succeed.  Quiz: what is the result of the following matches?
  • 14. Pattern matching  5=5.  {Name, Age, _} = {“Osama”, 28, cairo }.  [1,2] = {1, 2}.  "hello" = "hello".  "ABC" = [65, 66, 67].  $a = a.
  • 15. More pattern matching quizzes  X=5.  X=5. Y=X+1. Y=3+3.  X=Y. Y=1.  { X, Y } = { 5, 6 }  { Y, Y } = { 5, 6 } (When testing these on Erlang; remember to use f( ) to reset variable bindings.)
  • 16. Pattern matching on lists  [ H | T ] = [1, 2, 3].  [ H | T ] = [ ].  [ H | T ] = [1, 2].  [ H1, H2 | T ] = [1, 2, 3].  [ H1, H2 | T ] = [1, 2].  [A, B] ++ [ H| T] = "faculty".  "Mustafa" ++ X = "Mustafa Kamel".
  • 17. Some simple I/O io:format(fmt_str, [arg0,arg1... ])  Examples:  io:format("The results are ~p and ~p", [15, 16]).  io:format("Hello world ~n", [ ]).  io:format("Hello world ~n").  Codes:  ~~ : The '~' mark (needs no argument)  ~f : Format argument as floating point  ~c : Format argument as a character.  ~w : Format argument in standard syntax (i.e like terms in the language)  ~p : Standard syntax for printing (e.g turns lists of printable characters into strings)  ~n : newline character (doesn't need an argument).  Much more detail in the documentation. Erlang has very rich formatting features.
  • 18. More simple I/O io:get_line(Prompt) -> Data | eof | {error,Reason}  Gets a line from standard input as a string (includes the newline character). io:read(Prompt) → {ok, Term} | eof | {error, ErrorInfo}  Reads a term from standard input (user must include ending period). io:fread(Prompt, Format) -> {ok, Terms} | eof | {error, What}  Reads characters and returns a list of terms, parsed according to the specified format specification (different from that of io:format).  Examples:  io:read("Enter a point>"). Enter a point>{13, 14}. {ok, {13, 14}}  io:get_line("Enter your name>"). Enter your name>Captain Majid “Captain Majidn"  io:format( ), io:read( ) and all the other given i/o functions have additional parameters that can make them read from I/O devices like files...etc
  • 19. Modules -module(addition). -export([add/2, add/3]). add(X, Y) -> X+Y. add(X, Y, Z) -> X+Y+Z. unused_func( ) -> io:format("unused!"). % End of module definition.  Erlang code is divided into modules.  A module has attributes at the top (the begin with the dash character '-') and is followed by function declarations. Both attributes and declaration end with a dot '.'  Exported function names must include its artiy (number of parameters).  Two functions with the same name but different arities are different functions!
  • 20. Functions  add(A, B) → A+B. − Return value is the function's expression  add(A, B) → io:format(“now adding ~p and ~p~n", [A, B]), A+B. − In case of multiple expressions, return value is the last one
  • 21. Functions  absolute(A) when A>0 → 1 ; absolute(A) when A=0 → 0 ; absolute(A) → -1 .  The expressions after when are called guard sequences. More about them in the Erlang language reference → Expressions → Guard sequences
  • 22. Pattern matching in functions  distance({X1 Y1}, {X2, Y2}) → Dx= X1-X2, Dy= Y1-Y2, math:sqrt(Dx*Dx + Dy*Dy).  Tuples can be confusing (e.g is a tuple of two numbers a point, vector or age & salary?).  We can use an atom in the beginning (the tag) to distinguish between kinds of data...
  • 23. Pattern matching in functions  distance({point, X1, Y1}, {point, X2, Y2}) → Dx= X1-X2, Dy= Y1-Y2, math:sqrt(Dx*Dx + Dy*Dy).  example:distance({point, 0, 0}, {point, 100, 100}).
  • 24. Recursion factorial(0) ->1 ; factorial(N) -> N*factorial(N-1).  Function calls, activation records, and why this works.  We need this; we don't have loops !  The space requirements of naïve recursion.
  • 25. Recursion  Tail calls vs. non tail calls.  Tails calls are not only about recursion, but any function call.  Tail call elimination. Now recursion can be as good as loops.  In fact, it's can be compiled to jump instructions.  Sometimes it can be much better than loops!  Example: state machines
  • 26. Next...  Processes!  Actors!  Ping pong! − Thursday, 11 February 2010.