SlideShare une entreprise Scribd logo
1  sur  19
Erlang – Quick Intro Brought to you by Raymond Tay
Erlang? Small language designed more than 20 years ago by Joe Armstrong, Robert Virding and Mike Williams of Ericsson’s CS Lab.  Functional Language. Lightweight concurrency model (aka Actors). Yes, Scalahas a Actors model where they share similar syntax and machinery. Great for soft real-time systems. E.g. Second Life’s chat service Not good for number crunching. There are better tools for that e.g. SciPyNumPy
Yah yah yah…WHO actually uses Erlang? Amazon uses Erlang to implement SimpleDB as part of its EC2 services Facebook uses Erlang to power its backend chat service for its 100 million active users Ericsson uses Erlang to support its GPRS and 3G mobile networks T-Mobile uses Erlang in its SMS and authentication systems
So, what are the benefits of Erlang? Easy to learn, easy to use. Expressing distributing computing is easier Garbage collection is implemented on a per process basis An process in Erlang is light-weight i.e. not a OS process. Each pair of processes communicate by passing messages Designed to operate behind firewalls. Think private compute cloud
Let’s learn how Erlang does it Numbers Variables (they’re not variable) Atoms Boolean Algebra and Comparison Operators Tuples Lists (and comprehensions) Modules in Erlang
There’s more… High-order functions and Lambdas Errors and catching them (We don’t have time for this) Concurrency in Erlang and Actors etc (We don’t have time for this too) Finally we’ll end with a demonstration
Working with Erlang In FP, statements do not exist only expressions. Expressions always return a result and more often than not, have no side effects at all; statements (depending on the lang) may / may not return a result but always have side effects. Expressions, in Erlang, have to be terminated with a period followed by whitespace (,) E.g expression involving numbers 2 + 5. 5 / 2. (same as 5 div 2.) 5 rem 2.  -50 * (100 – 499). (Erlang understands the typical math operator precedences) 2#101 (same as the decimal number 5 only expressed in binary i.e. base 2) 16#cafebabe (do you know what this magic number is expressed in base 16?)
Variables in Erlang (seriously???) No such thing as a variable variable In Erlang, creating a variable and associating with a value is termed bounding. You cannot change the value once bounded. One = 1. One = 2. (Will not succeed) Two = 2. Two = One + One. (Will succeed) _ = 999999999 (Will always succeed. ‘_’ is the i-don’t-care-variable) The ‘=‘ acts as an assignment and pattern matching operator. Pattern matching occurs with/without the ‘=‘. More later.
Atoms (Like the physics term but not like it) In physics of the 1920s, atoms were the smallest things known to man. Today, there are units smaller than the atom like hadrons, quarks. In Erlang, an atom is a literal. hello. (Typing Hello. means to extract the value of Hello) ‘Hello there’. (anything in quotes is an atom) ‘_this_is_a_#really_!long_@string’.
Boolean Algebra, Operators In Erlang, the atom true is Truth whereas false is Falsehood. You can use =:= and =/= for comparing equality and inquality You can use == and /= for comparing equality and inequality if you don’t care about exactness / precisions 5 =:= 5. (will return true) 5 == 5. (will return true) 5 =:= 5.0. (will return false) 5 == 5.0. (will return true)
Tuples They allow you to aggregate values to form some sort of data structure. X = 10, Y = 4. Point = {X, Y}. (Tuple is created) {MyX, _} = Point. (Pattern matching at play. MyX will get the value 10) {_, _, _} = Point. (will fail and erlang will complain RHS don’t match LHS)
Lists In FP, lists are completely indispensable. Same here You can create lists, obviously. You can concat, intersect them. You can retrieve the head or tail of a list via ‘hd’ and ‘tl’ commands in the ‘erlang’ module MyList = [1,2,3,4,5]. MyList ++ [7,8] - - [1,2,3,4,5,6,78]. (equivalent to (MyList ++ ([7,8] - - [1,2,3,4,5,6,7,8])) ) hd( [1,2] ). (will return 1 and take note its not a list) tl([1,2]). (will return [2] which is a list)
List Comprehension In other languages, its called a for-comprehension. Let’s look at code examples [2 * N | | N <- [1,2,3]]. (returns [2,4,6]) [X | | X <- [1,2,3,4,5,6], X rem 2 =:= 0]. (returns [2,4,6] ) Let’s look at a more complex example (taken from sg.finance.yahoo.com) [ {Quote,Price} | | {Quote, Price} <- [ {e3s, 0.4}, {g13.si, 1.66}, {'5im.si',0.22}, {e5h.si, 0.64} ], Price > 0.5]. (returns [{'g13.si',1.66},{'e5h.si',0.64}]) Nested-for-loops (Ugly word in Erlang, but u get the meaning) [ {X, Y} | | X <- [1,2], Y <- [3,4]]. (returns [{1,3}, {1,4}, {2,3}, {2,4}])
How to avoid clustering all code in a single file? You need modules. You need to declare your module’s name, attributes, what functions are exported
Compiling and using your modules There are a couple of methods to do this but for the sake of brevity, here’s the simplest
Functions and Lambdas Functions are easy to write in Erlang. You don’t need to say ‘def’, ‘function’ or give any access specifier like ‘public’, ‘protected’ any of that nonsense. Here’s an example of a Mapper function. map(_, []) -> []; map(F, [H|T]) -> [F(H) | map(F, T)]. Another example of a Folder function fold(F, Start, []) -> Start; fold(F, Start, [H|T]) -> fold(F, F(H, Start), T). A lambda function is simply a nameless function and sometimes called an anonymous function. They can do pretty much anything except recursion. The form is like this: fun (Args1) -> Expression1, … , Expression N ;        (Args2) -> Expression1, … , Expression N; end.
Lambdas
More Lambdas…
Demo This is a demo of a sorting algorithm I wrote in 2007 as it illustrates most of the concepts we talked about.

Contenu connexe

Tendances

Applicative Functor - Part 2
Applicative Functor - Part 2Applicative Functor - Part 2
Applicative Functor - Part 2Philip Schwarz
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1Philip Schwarz
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5Infinity Tech Solutions
 
‘go-to’ general-purpose sequential collections - from Java To Scala
‘go-to’ general-purpose sequential collections -from Java To Scala‘go-to’ general-purpose sequential collections -from Java To Scala
‘go-to’ general-purpose sequential collections - from Java To ScalaPhilip Schwarz
 
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1Philip Schwarz
 
The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)Scott Wlaschin
 
The swift programming language
The swift programming languageThe swift programming language
The swift programming languagePardeep Chaudhary
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 Bdplunkett
 
The Power Of Composition (DotNext 2019)
The Power Of Composition (DotNext 2019)The Power Of Composition (DotNext 2019)
The Power Of Composition (DotNext 2019)Scott Wlaschin
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2dplunkett
 
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 JavaRasan Samarasinghe
 
Clean code lecture part I
Clean code lecture part IClean code lecture part I
Clean code lecture part IJun Shimizu
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3dplunkett
 
Compositionality and Category Theory - a montage of slides/transcript for sec...
Compositionality and Category Theory - a montage of slides/transcript for sec...Compositionality and Category Theory - a montage of slides/transcript for sec...
Compositionality and Category Theory - a montage of slides/transcript for sec...Philip Schwarz
 
The Power of Composition
The Power of CompositionThe Power of Composition
The Power of CompositionScott Wlaschin
 

Tendances (20)

Applicative Functor - Part 2
Applicative Functor - Part 2Applicative Functor - Part 2
Applicative Functor - Part 2
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1
 
Q2
Q2Q2
Q2
 
Anfis (1)
Anfis (1)Anfis (1)
Anfis (1)
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5
 
Database management system session 5
Database management system session 5Database management system session 5
Database management system session 5
 
‘go-to’ general-purpose sequential collections - from Java To Scala
‘go-to’ general-purpose sequential collections -from Java To Scala‘go-to’ general-purpose sequential collections -from Java To Scala
‘go-to’ general-purpose sequential collections - from Java To Scala
 
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1
 
The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)
 
The swift programming language
The swift programming languageThe swift programming language
The swift programming language
 
Ap Power Point Chpt3 B
Ap Power Point Chpt3 BAp Power Point Chpt3 B
Ap Power Point Chpt3 B
 
The Power Of Composition (DotNext 2019)
The Power Of Composition (DotNext 2019)The Power Of Composition (DotNext 2019)
The Power Of Composition (DotNext 2019)
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
 
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
 
Clean code lecture part I
Clean code lecture part IClean code lecture part I
Clean code lecture part I
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3
 
Compositionality and Category Theory - a montage of slides/transcript for sec...
Compositionality and Category Theory - a montage of slides/transcript for sec...Compositionality and Category Theory - a montage of slides/transcript for sec...
Compositionality and Category Theory - a montage of slides/transcript for sec...
 
Regular expression for dfa
Regular expression for dfaRegular expression for dfa
Regular expression for dfa
 
DBMS CS3
DBMS CS3DBMS CS3
DBMS CS3
 
The Power of Composition
The Power of CompositionThe Power of Composition
The Power of Composition
 

En vedette (14)

Basic definitions of queuing theory seminar
Basic definitions of queuing theory seminarBasic definitions of queuing theory seminar
Basic definitions of queuing theory seminar
 
Queuing Theory - Operation Research
Queuing Theory - Operation ResearchQueuing Theory - Operation Research
Queuing Theory - Operation Research
 
Queueing theory
Queueing theoryQueueing theory
Queueing theory
 
QUEUING THEORY
QUEUING THEORYQUEUING THEORY
QUEUING THEORY
 
Why erlang
Why erlangWhy erlang
Why erlang
 
Mobile phones
Mobile phonesMobile phones
Mobile phones
 
Erlang: Software for a Concurrent world
Erlang: Software for a Concurrent worldErlang: Software for a Concurrent world
Erlang: Software for a Concurrent world
 
Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlang
 
Intro to Erlang
Intro to ErlangIntro to Erlang
Intro to Erlang
 
Queuing problems
Queuing problemsQueuing problems
Queuing problems
 
Queueing theory
Queueing theoryQueueing theory
Queueing theory
 
QUEUING THEORY
QUEUING THEORY QUEUING THEORY
QUEUING THEORY
 
Queuing theory
Queuing theoryQueuing theory
Queuing theory
 
Queueing Theory and its BusinessS Applications
Queueing Theory and its BusinessS ApplicationsQueueing Theory and its BusinessS Applications
Queueing Theory and its BusinessS Applications
 

Similaire à Introduction to Erlang

Erlang kickstart
Erlang kickstartErlang kickstart
Erlang kickstartRyan Brown
 
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
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameAntony Stubbs
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Introduction to Erlang Part 1
Introduction to Erlang Part 1Introduction to Erlang Part 1
Introduction to Erlang Part 1Dmitry Zinoviev
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxpriestmanmable
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II PresentationKnoldus Inc.
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II PresentationKnoldus Inc.
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20Max Kleiner
 
c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and SelectionAhmed Nobi
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Tiểu Hổ
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming hccit
 

Similaire à Introduction to Erlang (20)

Erlang kickstart
Erlang kickstartErlang kickstart
Erlang kickstart
 
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...
 
Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love Game
 
Erlang session1
Erlang session1Erlang session1
Erlang session1
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
外傷的Elixir
外傷的Elixir外傷的Elixir
外傷的Elixir
 
Module 2 topic 1 notes
Module 2 topic 1 notesModule 2 topic 1 notes
Module 2 topic 1 notes
 
java_lect_03-2.ppt
java_lect_03-2.pptjava_lect_03-2.ppt
java_lect_03-2.ppt
 
Introduction to Erlang Part 1
Introduction to Erlang Part 1Introduction to Erlang Part 1
Introduction to Erlang Part 1
 
3.5
3.53.5
3.5
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
 
c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and Selection
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3
 
Elixir
ElixirElixir
Elixir
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming
 

Plus de Raymond Tay

Principled io in_scala_2019_distribution
Principled io in_scala_2019_distributionPrincipled io in_scala_2019_distribution
Principled io in_scala_2019_distributionRaymond Tay
 
Building a modern data platform with scala, akka, apache beam
Building a modern data platform with scala, akka, apache beamBuilding a modern data platform with scala, akka, apache beam
Building a modern data platform with scala, akka, apache beamRaymond Tay
 
Toying with spark
Toying with sparkToying with spark
Toying with sparkRaymond Tay
 
Distributed computing for new bloods
Distributed computing for new bloodsDistributed computing for new bloods
Distributed computing for new bloodsRaymond Tay
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scalaRaymond Tay
 
Introduction to cuda geek camp singapore 2011
Introduction to cuda   geek camp singapore 2011Introduction to cuda   geek camp singapore 2011
Introduction to cuda geek camp singapore 2011Raymond Tay
 
Introduction to CUDA
Introduction to CUDAIntroduction to CUDA
Introduction to CUDARaymond Tay
 

Plus de Raymond Tay (8)

Principled io in_scala_2019_distribution
Principled io in_scala_2019_distributionPrincipled io in_scala_2019_distribution
Principled io in_scala_2019_distribution
 
Building a modern data platform with scala, akka, apache beam
Building a modern data platform with scala, akka, apache beamBuilding a modern data platform with scala, akka, apache beam
Building a modern data platform with scala, akka, apache beam
 
Practical cats
Practical catsPractical cats
Practical cats
 
Toying with spark
Toying with sparkToying with spark
Toying with spark
 
Distributed computing for new bloods
Distributed computing for new bloodsDistributed computing for new bloods
Distributed computing for new bloods
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scala
 
Introduction to cuda geek camp singapore 2011
Introduction to cuda   geek camp singapore 2011Introduction to cuda   geek camp singapore 2011
Introduction to cuda geek camp singapore 2011
 
Introduction to CUDA
Introduction to CUDAIntroduction to CUDA
Introduction to CUDA
 

Dernier

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Dernier (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Introduction to Erlang

  • 1. Erlang – Quick Intro Brought to you by Raymond Tay
  • 2. Erlang? Small language designed more than 20 years ago by Joe Armstrong, Robert Virding and Mike Williams of Ericsson’s CS Lab. Functional Language. Lightweight concurrency model (aka Actors). Yes, Scalahas a Actors model where they share similar syntax and machinery. Great for soft real-time systems. E.g. Second Life’s chat service Not good for number crunching. There are better tools for that e.g. SciPyNumPy
  • 3. Yah yah yah…WHO actually uses Erlang? Amazon uses Erlang to implement SimpleDB as part of its EC2 services Facebook uses Erlang to power its backend chat service for its 100 million active users Ericsson uses Erlang to support its GPRS and 3G mobile networks T-Mobile uses Erlang in its SMS and authentication systems
  • 4. So, what are the benefits of Erlang? Easy to learn, easy to use. Expressing distributing computing is easier Garbage collection is implemented on a per process basis An process in Erlang is light-weight i.e. not a OS process. Each pair of processes communicate by passing messages Designed to operate behind firewalls. Think private compute cloud
  • 5. Let’s learn how Erlang does it Numbers Variables (they’re not variable) Atoms Boolean Algebra and Comparison Operators Tuples Lists (and comprehensions) Modules in Erlang
  • 6. There’s more… High-order functions and Lambdas Errors and catching them (We don’t have time for this) Concurrency in Erlang and Actors etc (We don’t have time for this too) Finally we’ll end with a demonstration
  • 7. Working with Erlang In FP, statements do not exist only expressions. Expressions always return a result and more often than not, have no side effects at all; statements (depending on the lang) may / may not return a result but always have side effects. Expressions, in Erlang, have to be terminated with a period followed by whitespace (,) E.g expression involving numbers 2 + 5. 5 / 2. (same as 5 div 2.) 5 rem 2. -50 * (100 – 499). (Erlang understands the typical math operator precedences) 2#101 (same as the decimal number 5 only expressed in binary i.e. base 2) 16#cafebabe (do you know what this magic number is expressed in base 16?)
  • 8. Variables in Erlang (seriously???) No such thing as a variable variable In Erlang, creating a variable and associating with a value is termed bounding. You cannot change the value once bounded. One = 1. One = 2. (Will not succeed) Two = 2. Two = One + One. (Will succeed) _ = 999999999 (Will always succeed. ‘_’ is the i-don’t-care-variable) The ‘=‘ acts as an assignment and pattern matching operator. Pattern matching occurs with/without the ‘=‘. More later.
  • 9. Atoms (Like the physics term but not like it) In physics of the 1920s, atoms were the smallest things known to man. Today, there are units smaller than the atom like hadrons, quarks. In Erlang, an atom is a literal. hello. (Typing Hello. means to extract the value of Hello) ‘Hello there’. (anything in quotes is an atom) ‘_this_is_a_#really_!long_@string’.
  • 10. Boolean Algebra, Operators In Erlang, the atom true is Truth whereas false is Falsehood. You can use =:= and =/= for comparing equality and inquality You can use == and /= for comparing equality and inequality if you don’t care about exactness / precisions 5 =:= 5. (will return true) 5 == 5. (will return true) 5 =:= 5.0. (will return false) 5 == 5.0. (will return true)
  • 11. Tuples They allow you to aggregate values to form some sort of data structure. X = 10, Y = 4. Point = {X, Y}. (Tuple is created) {MyX, _} = Point. (Pattern matching at play. MyX will get the value 10) {_, _, _} = Point. (will fail and erlang will complain RHS don’t match LHS)
  • 12. Lists In FP, lists are completely indispensable. Same here You can create lists, obviously. You can concat, intersect them. You can retrieve the head or tail of a list via ‘hd’ and ‘tl’ commands in the ‘erlang’ module MyList = [1,2,3,4,5]. MyList ++ [7,8] - - [1,2,3,4,5,6,78]. (equivalent to (MyList ++ ([7,8] - - [1,2,3,4,5,6,7,8])) ) hd( [1,2] ). (will return 1 and take note its not a list) tl([1,2]). (will return [2] which is a list)
  • 13. List Comprehension In other languages, its called a for-comprehension. Let’s look at code examples [2 * N | | N <- [1,2,3]]. (returns [2,4,6]) [X | | X <- [1,2,3,4,5,6], X rem 2 =:= 0]. (returns [2,4,6] ) Let’s look at a more complex example (taken from sg.finance.yahoo.com) [ {Quote,Price} | | {Quote, Price} <- [ {e3s, 0.4}, {g13.si, 1.66}, {'5im.si',0.22}, {e5h.si, 0.64} ], Price > 0.5]. (returns [{'g13.si',1.66},{'e5h.si',0.64}]) Nested-for-loops (Ugly word in Erlang, but u get the meaning) [ {X, Y} | | X <- [1,2], Y <- [3,4]]. (returns [{1,3}, {1,4}, {2,3}, {2,4}])
  • 14. How to avoid clustering all code in a single file? You need modules. You need to declare your module’s name, attributes, what functions are exported
  • 15. Compiling and using your modules There are a couple of methods to do this but for the sake of brevity, here’s the simplest
  • 16. Functions and Lambdas Functions are easy to write in Erlang. You don’t need to say ‘def’, ‘function’ or give any access specifier like ‘public’, ‘protected’ any of that nonsense. Here’s an example of a Mapper function. map(_, []) -> []; map(F, [H|T]) -> [F(H) | map(F, T)]. Another example of a Folder function fold(F, Start, []) -> Start; fold(F, Start, [H|T]) -> fold(F, F(H, Start), T). A lambda function is simply a nameless function and sometimes called an anonymous function. They can do pretty much anything except recursion. The form is like this: fun (Args1) -> Expression1, … , Expression N ; (Args2) -> Expression1, … , Expression N; end.
  • 19. Demo This is a demo of a sorting algorithm I wrote in 2007 as it illustrates most of the concepts we talked about.