SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
Elixir
Robert Brown
@robby_brown
@robert_brown
@rob-brown
What is Elixir?
A Ruby-inspired language built on the Erlang Virtual
Machine
Extends Erlang with macros, pipelines, and sigils
Your next programming language
What is Erlang?
Created in 1986 by Ericsson
Open sourced in 1998
Functional, concurrent language
Based on Prolog, Smalltalk, CSP, and functional
programming
Advantages of Erlang
Fault tolerant
Lightweight processes
Hot code swapping
“Let it crash” philosophy
Advantages of Erlang
Battle-tested libraries
Soft real time
Trivial parallel processing
Trivial network protocol processing
Advantages of Erlang
Pattern matching
Tail recursion
Garbage Collected
Advantages of Erlang
http://www.slideshare.net/JanHenryNystrom/productivity-gains-in-erlang
Who Uses Erlang?
Amazon
Yahoo!
Facebook
T-Mobile
Motorola
Ericsson
WhatsApp
Huffington Post
CouchDB
GitHub
Basho
RabbitMQ
Call of Duty
League of
Legends
Goldman Sachs
http://en.wikipedia.org/wiki/Erlang_(programming_language)
Why Learn Functional
Programming?
The future is in parallel processing
Easier to debug
Many languages are adopting FP techniques
Actor Model
Actors can be created/destroyed and send/receive
messages
All state is encapsulated
In Elixir, each actor is its own process
Elixir Syntax: Numbers
!
42
123.456
1_000_000
!
0b101010 (binary)
0xdeadc0de (hex)
034 (octal)
Elixir Syntax: Tuples
{ 1, 2, 3 }
{ 3.14, :hello, “world” }
Elixir Syntax: List
[ ]
[ 1, 2, 3 ]
[ head | tail ]
[ first, second | tail ]
Elixir Syntax: Atom
:atom
:“with spaces”
Elixir Syntax: Binary
“Elixir”
<<“Elixir”>>
<< 69, 108, 105, 120, 105, 114 >>
Elixir Syntax: Character List
‘Elixir’
[ ?E, ?l, ?i, ?x, ?i, ?r ]
[ 69, 108, 105, 120, 105, 114 ]
Elixir Syntax: Range
1..100
10..0
-10..10
Elixir Syntax: Pipeline
IO.puts(“Hello world!”)
“Hello world!” |> IO.puts()
!
IO.puts(String.upcase(“Elixir”))
“Elixir” |> String.upcase() |> IO.puts()
Elixir Syntax: Regex
~r“^[A-Z]$”
“101010” =~ ~r“^[01]+$”
Elixir Syntax: Operators
+ - * / ! = == === != !== > >= < <=
and or xor not
&& ||
[ 1, 2, 3 ] ++ [ 4, 5, 6 ]
[ 1, 2, 3 ] -- [ 2 ]
“Hello ” <> “World!”
Elixir Syntax: Fn
fn (x) -> x * x end
&(&1 * &1)
!
fn (x, y) -> x + y * 2 end
&(&1 + &2 * 2)
Elixir Syntax:
Modules and Functions
defmodule Demo do
def say_hello() do
IO.puts(“Hello”)
end
def say_goodbye(), do: IO.puts(“Goodbye”)
defp private_function(), do: “Top Secret”
end
Pattern Matching
“=” operator does not mean “assign”
It’s the matching operator
Think of “=” in terms of math
Pattern Matching
x = 42
[ a, b, c ] = [ 1, 2, 3 ]
[ d, d, e ] = [ 4, 4, 5 ]
{ ^x, y } = { 42, 99 }
Pattern Matching
{ :ok, data } = File.read(“Demo.txt”)
{ :error, reason } = File.read(“Bogus.txt”)
{ a, b, _ } = Demo.do_something()
Pattern Matching
def sum(list), do: _sum(list, 0)
defp _sum([], total), do: total
defp _sum([ head | tail ], total) do
_sum(tail, head + total)
end
Pattern Matching
fn (x) when rem(x, 15) == 0 -> “FizzBuzz”
(x) when rem(x, 3) == 0 -> “Fizz”
(x) when rem(x, 5) == 0 -> “Buzz”
(x) -> x
end
Pattern Matching
<< number::[ bitstring, size(16) ],
“ ”,
word::[ bitstring, size(48) ] >> =
“42 Elixir”
PID
Process ID
Returned from spawn and spawn_link
Transfer messages with send and receive
PID: spawn
pid = spawn(fn -> do_something() end)
pid = spawn(Demo, :do_something, [])
pid = spawn(&Demo.do_something/0)
pid = spawn_link(fn -> 1 / 0 end)
PID: send
send(pid, 42)
send(pid, { self, :something })
send(pid, { self, fn (x) -> x * x end })
PID: receive
receive do
{ from, :something } ->
send(from, { self, do_something() }
{ :EXIT, from, reason } ->

IO.puts(“#{from} died by #{reason}”)
after 60 * 1000 ->
:timeout
end
Questions?
Demo
Want to Learn More?
Elixir Lang
Elixir Cheat Sheet
Programming Elixir
Programming Erlang
Want to Learn More?
!
Productivity Gains In Erlang
Joe Armstrong
Evan Miller
Russel Dillin

Más contenido relacionado

La actualidad más candente

What's new in Ruby 2.0
What's new in Ruby 2.0What's new in Ruby 2.0
What's new in Ruby 2.0
Kartik Sahoo
 

La actualidad más candente (20)

Awesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir TasksAwesome Concurrency with Elixir Tasks
Awesome Concurrency with Elixir Tasks
 
Use the @types, Luke
Use the @types, LukeUse the @types, Luke
Use the @types, Luke
 
effective_r27
effective_r27effective_r27
effective_r27
 
Elixir and elm
Elixir and elmElixir and elm
Elixir and elm
 
Xtext beyond the defaults - how to tackle performance problems
Xtext beyond the defaults -  how to tackle performance problemsXtext beyond the defaults -  how to tackle performance problems
Xtext beyond the defaults - how to tackle performance problems
 
What's new in Ruby 2.0
What's new in Ruby 2.0What's new in Ruby 2.0
What's new in Ruby 2.0
 
A (very brief) into to Functional Programming
A (very brief) into to Functional ProgrammingA (very brief) into to Functional Programming
A (very brief) into to Functional Programming
 
Elm kyivfprog 2015
Elm kyivfprog 2015Elm kyivfprog 2015
Elm kyivfprog 2015
 
Functional programming with Xtend
Functional programming with XtendFunctional programming with Xtend
Functional programming with Xtend
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...
 
Future of Kotlin - How agile can language development be?
Future of Kotlin - How agile can language development be?Future of Kotlin - How agile can language development be?
Future of Kotlin - How agile can language development be?
 
C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Enrich Your Models With OCL
Enrich Your Models With OCLEnrich Your Models With OCL
Enrich Your Models With OCL
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
Giving Clarity to LINQ Queries by Extending Expressions
Giving Clarity to LINQ Queries by Extending ExpressionsGiving Clarity to LINQ Queries by Extending Expressions
Giving Clarity to LINQ Queries by Extending Expressions
 
OCL in EMF
OCL in EMFOCL in EMF
OCL in EMF
 
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/OTech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
Tech Webinar: AUMENTARE LA SCALABILITÀ DELLE WEB APP CON SERVLET 3.1 ASYNC I/O
 
Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
 

Destacado

An introduction to Erlang and Elixir
An introduction to Erlang and ElixirAn introduction to Erlang and Elixir
An introduction to Erlang and Elixir
ericbmerritt
 

Destacado (20)

Elixir Consulting Profile
Elixir Consulting ProfileElixir Consulting Profile
Elixir Consulting Profile
 
Growing ELIXIR-UK
Growing ELIXIR-UKGrowing ELIXIR-UK
Growing ELIXIR-UK
 
Enfermedades raras
Enfermedades rarasEnfermedades raras
Enfermedades raras
 
Enfermedades RARAS
Enfermedades RARASEnfermedades RARAS
Enfermedades RARAS
 
Functional Programming With Elixir
Functional Programming With ElixirFunctional Programming With Elixir
Functional Programming With Elixir
 
Las Enfermedades Raras
Las Enfermedades Raras Las Enfermedades Raras
Las Enfermedades Raras
 
The ELIXIR UK training portal (TeSS) by Carole Goble
The ELIXIR UK training portal (TeSS) by Carole GobleThe ELIXIR UK training portal (TeSS) by Carole Goble
The ELIXIR UK training portal (TeSS) by Carole Goble
 
Introducción a las Enfermedades Raras - 27.03.2015
Introducción a las Enfermedades Raras - 27.03.2015Introducción a las Enfermedades Raras - 27.03.2015
Introducción a las Enfermedades Raras - 27.03.2015
 
Coordinating European training and ELIXIR UK by Rita Hendricusdottir
Coordinating European training and ELIXIR UK by Rita HendricusdottirCoordinating European training and ELIXIR UK by Rita Hendricusdottir
Coordinating European training and ELIXIR UK by Rita Hendricusdottir
 
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
TeSS: ELIXIR Training Portal (Eubic Winter School 2017)
 
An introduction to Erlang and Elixir
An introduction to Erlang and ElixirAn introduction to Erlang and Elixir
An introduction to Erlang and Elixir
 
Enfermedades raras II
Enfermedades raras IIEnfermedades raras II
Enfermedades raras II
 
La Estrategia en Enfermedades Raras del SNS
La Estrategia en Enfermedades Raras del SNSLa Estrategia en Enfermedades Raras del SNS
La Estrategia en Enfermedades Raras del SNS
 
Enfermedades Raras y Crónicas
Enfermedades Raras y CrónicasEnfermedades Raras y Crónicas
Enfermedades Raras y Crónicas
 
¿Qué son las Enfermedades Raras?
¿Qué son las Enfermedades Raras?¿Qué son las Enfermedades Raras?
¿Qué son las Enfermedades Raras?
 
Medición en salud
Medición en saludMedición en salud
Medición en salud
 
Validacion de escalas de medicion en salud
Validacion de escalas de medicion en saludValidacion de escalas de medicion en salud
Validacion de escalas de medicion en salud
 
Enfermedades raras i
Enfermedades raras iEnfermedades raras i
Enfermedades raras i
 
Medicamentos huérfanos
Medicamentos huérfanosMedicamentos huérfanos
Medicamentos huérfanos
 
Enfermedades raras
Enfermedades rarasEnfermedades raras
Enfermedades raras
 

Similar a Elixir

Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
guest3933de
 

Similar a Elixir (20)

Elixir introduction
Elixir introductionElixir introduction
Elixir introduction
 
Introducing Elixir and OTP at the Erlang BASH
Introducing Elixir and OTP at the Erlang BASHIntroducing Elixir and OTP at the Erlang BASH
Introducing Elixir and OTP at the Erlang BASH
 
Origins of Elixir programming language
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming language
 
Erlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web WisdomErlang plus BDB: Disrupting the Conventional Web Wisdom
Erlang plus BDB: Disrupting the Conventional Web Wisdom
 
Disrupt
DisruptDisrupt
Disrupt
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 
ppt9
ppt9ppt9
ppt9
 
Intro to Elixir talk
Intro to Elixir talkIntro to Elixir talk
Intro to Elixir talk
 

Más de Robert Brown

Más de Robert Brown (14)

High level concurrency
High level concurrencyHigh level concurrency
High level concurrency
 
Data Source Combinators
Data Source CombinatorsData Source Combinators
Data Source Combinators
 
MVVM
MVVMMVVM
MVVM
 
Reactive Cocoa
Reactive CocoaReactive Cocoa
Reactive Cocoa
 
UIKit Dynamics
UIKit DynamicsUIKit Dynamics
UIKit Dynamics
 
iOS State Preservation and Restoration
iOS State Preservation and RestorationiOS State Preservation and Restoration
iOS State Preservation and Restoration
 
Anti-Patterns
Anti-PatternsAnti-Patterns
Anti-Patterns
 
Pragmatic blocks
Pragmatic blocksPragmatic blocks
Pragmatic blocks
 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference Counting
 
Grand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsGrand Central Dispatch Design Patterns
Grand Central Dispatch Design Patterns
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
 
Mac/iOS Design Patterns
Mac/iOS Design PatternsMac/iOS Design Patterns
Mac/iOS Design Patterns
 
Core Data
Core DataCore Data
Core Data
 
Quick Look for iOS
Quick Look for iOSQuick Look for iOS
Quick Look for iOS
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Elixir