SlideShare una empresa de Scribd logo
1 de 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.

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Más 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
 

Más 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
 

Último

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
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 cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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 cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

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.