SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Elixir
Abdulsattar - http://bimorphic.com
Features
Dynamic
Functional
Pattern Matching
Ruby inspired syntax
Extensible: macros
Concurrency, Distributed and Fault tolerant
Data Types/Structures
1 # integer
2.0 # float
true # boolean
:atom # atom / symbol
'elixir' # character list
"elixir" # string
[1, 2, 3] # list
{1,2} # tuple
[{:a, 1}, {:b, 2}] # keyword list
[a: 1, b: 2] # ^ same keyword list
%{a: 1, b: 2, c: 3} # hash
Pattern Matching
a = 1
{x, y} = {0, 0}
[head | tail] = [1, 2, 3]
result = case {1, 2, 3} do
{4, 5, 6} -> "Doesn't match"
{1, x, 3} when x > 3 -> "doesn't match because 2 < 3"
{x, 2, 3} -> "matches and x is #{x}"
_ -> "matches if nothing above matches"
end
def zero?(0), do: true
def zero?(x) when is_number(x), do: false
Modules
defmodule Math do
def sum(a, b) do
a + b
end
def sub(a, b) do
a - b
end
end
IO.puts (Math.sum(3,4))
Structs
defmodule Person do
defstruct name: "Sattar", age: 40
end
me = %Person{name: "AbdulSattar"}
IO.puts me.name # Abdulsattar
%Person{name: name, age: age} = me
IO.puts(age) # 40
youngMe = %{me | age: 10}
Protocols
defprotocol Blank do
@doc "Returns true if data is considered blank/empty"
def blank?(data)
end
defimpl Blank, for: Integer do
def blank?(0), do: true
def blank?(_), do: false
end
defimpl Blank, for: List do
def blank?([]), do: true
def blank?(_), do: false
end
Blank.blank?(3) # false
Blank.blank?([]) # true
Enumerables
iex(2)> Enum.map([1, 2, 3], fn x -> x * x end)
[1, 4, 9]
iex(3)> Enum.map([1, 2, 3], &(&1 * &1))
[1, 4, 9]
iex(4)> Enum.reduce(1..100, 0, &+/2)
5050
Pipe Operator
sumOfSquares = Enum.reduce(Enum.map(1..100, fn x -> x * x end), 0, &+/2)
sumOfSquares1 = 1..100
|> Enum.map(fn x -> x * x end)
|> Enum.reduce(0, &+/2)
square = fn x -> x * x end
sumOfSquares2 = 1..100
|> Enum.map(square)
|> Enum.sum
Macros
defmodule Unless do
defmacro macro_unless(clause, expression) do
quote do
if(!unquote(clause), do: unquote(expression))
end
end
end
Unless.macro_unless false, do: IO.puts "prints"
Unless.macro_unless true, do: IO.puts "doesn't print"
Processes
pid = spawn fn ->
receive do
msg -> IO.puts "Received: #{msg}"
end
end
send pid, "Hello!"
send pid, "3 times"
Supervisors
DEMO

Weitere ähnliche Inhalte

Was ist angesagt?

The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)
GroovyPuzzlers
 
Twittori - Tweets aus der Umgebung
Twittori - Tweets aus der UmgebungTwittori - Tweets aus der Umgebung
Twittori - Tweets aus der Umgebung
Twittwoch e.V.
 

Was ist angesagt? (9)

My First Data Science Project (Data Science Thailand Meetup #1)
My First Data Science Project (Data Science Thailand Meetup #1)My First Data Science Project (Data Science Thailand Meetup #1)
My First Data Science Project (Data Science Thailand Meetup #1)
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)
 
Open course(programming languages) 20150121
Open course(programming languages) 20150121Open course(programming languages) 20150121
Open course(programming languages) 20150121
 
Python an-intro youtube-livestream-day2
Python an-intro youtube-livestream-day2Python an-intro youtube-livestream-day2
Python an-intro youtube-livestream-day2
 
Writeable CTEs: The Next Big Thing
Writeable CTEs: The Next Big ThingWriteable CTEs: The Next Big Thing
Writeable CTEs: The Next Big Thing
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)
 
Iterators, Hashes, and Arrays
Iterators, Hashes, and ArraysIterators, Hashes, and Arrays
Iterators, Hashes, and Arrays
 
Twittori - Twittwoch Berlin
Twittori - Twittwoch BerlinTwittori - Twittwoch Berlin
Twittori - Twittwoch Berlin
 
Twittori - Tweets aus der Umgebung
Twittori - Tweets aus der UmgebungTwittori - Tweets aus der Umgebung
Twittori - Tweets aus der Umgebung
 

Andere mochten auch

班級經營100.03.30
班級經營100.03.30班級經營100.03.30
班級經營100.03.30
Kuo-Yi Chen
 
Мастердент
МастердентМастердент
Мастердент
osokolova
 
9 Frame Analysis - Biffy Clyro - Mountains
9 Frame Analysis - Biffy Clyro - Mountains9 Frame Analysis - Biffy Clyro - Mountains
9 Frame Analysis - Biffy Clyro - Mountains
alexhester
 
Greatest Hits 80s
Greatest Hits 80sGreatest Hits 80s
Greatest Hits 80s
PinkFloyd50
 

Andere mochten auch (20)

終身保證收入
終身保證收入終身保證收入
終身保證收入
 
Commercial Architecture
Commercial ArchitectureCommercial Architecture
Commercial Architecture
 
Marilyn Gardner Milton: Advanced Law School Chat Pt. 2
Marilyn Gardner Milton: Advanced Law School Chat Pt. 2Marilyn Gardner Milton: Advanced Law School Chat Pt. 2
Marilyn Gardner Milton: Advanced Law School Chat Pt. 2
 
班級經營100.03.30
班級經營100.03.30班級經營100.03.30
班級經營100.03.30
 
IoT Eindhoven Iskander Smit - Civic City
IoT Eindhoven Iskander Smit - Civic CityIoT Eindhoven Iskander Smit - Civic City
IoT Eindhoven Iskander Smit - Civic City
 
World Office Forum Alianza del Pacífico 2015
World Office Forum Alianza del Pacífico 2015World Office Forum Alianza del Pacífico 2015
World Office Forum Alianza del Pacífico 2015
 
7 reasons why media productivity plans don't work as expected
7 reasons why media productivity plans don't work as expected7 reasons why media productivity plans don't work as expected
7 reasons why media productivity plans don't work as expected
 
Мастердент
МастердентМастердент
Мастердент
 
Getting Started as a PM
Getting Started as a PMGetting Started as a PM
Getting Started as a PM
 
EEK! Halloween Activities for K to 5
EEK! Halloween Activities for K to 5EEK! Halloween Activities for K to 5
EEK! Halloween Activities for K to 5
 
Improving Promotion Effectiveness - Mindtree webinar
Improving Promotion Effectiveness - Mindtree webinarImproving Promotion Effectiveness - Mindtree webinar
Improving Promotion Effectiveness - Mindtree webinar
 
Hashtaggery BLC16
Hashtaggery BLC16Hashtaggery BLC16
Hashtaggery BLC16
 
9 Frame Analysis - Biffy Clyro - Mountains
9 Frame Analysis - Biffy Clyro - Mountains9 Frame Analysis - Biffy Clyro - Mountains
9 Frame Analysis - Biffy Clyro - Mountains
 
日本の名水
日本の名水日本の名水
日本の名水
 
Stampions Cross Media Cafe
Stampions Cross Media CafeStampions Cross Media Cafe
Stampions Cross Media Cafe
 
Finalaya daily wrap_01sep2014
Finalaya daily wrap_01sep2014Finalaya daily wrap_01sep2014
Finalaya daily wrap_01sep2014
 
Atividade - Mapa Conceitual
Atividade - Mapa ConceitualAtividade - Mapa Conceitual
Atividade - Mapa Conceitual
 
Atención
AtenciónAtención
Atención
 
Qualitem - Large List Support - SharePoint Saturday
Qualitem - Large List Support - SharePoint SaturdayQualitem - Large List Support - SharePoint Saturday
Qualitem - Large List Support - SharePoint Saturday
 
Greatest Hits 80s
Greatest Hits 80sGreatest Hits 80s
Greatest Hits 80s
 

Ähnlich wie Introducing Elixir

Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
Giovanni924
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
aztack
 

Ähnlich wie Introducing Elixir (20)

Elixir in a nutshell - Fundamental Concepts
Elixir in a nutshell - Fundamental ConceptsElixir in a nutshell - Fundamental Concepts
Elixir in a nutshell - Fundamental Concepts
 
Elixir formatter Internals
Elixir formatter InternalsElixir formatter Internals
Elixir formatter Internals
 
iRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat SheetiRODS Rule Language Cheat Sheet
iRODS Rule Language Cheat Sheet
 
Elixir pattern matching and recursion
Elixir pattern matching and recursionElixir pattern matching and recursion
Elixir pattern matching and recursion
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
R learning by examples
R learning by examplesR learning by examples
R learning by examples
 
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammersSlides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
 
Elixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicitElixir & Phoenix – fast, concurrent and explicit
Elixir & Phoenix – fast, concurrent and explicit
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
Django - sql alchemy - jquery
Django - sql alchemy - jqueryDjango - sql alchemy - jquery
Django - sql alchemy - jquery
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Ecto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii BodarevEcto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii Bodarev
 
Yurii Bodarev - Ecto DSL
Yurii Bodarev - Ecto DSLYurii Bodarev - Ecto DSL
Yurii Bodarev - Ecto DSL
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 

Kürzlich hochgeladen

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Kürzlich hochgeladen (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

Introducing Elixir

  • 2. Features Dynamic Functional Pattern Matching Ruby inspired syntax Extensible: macros Concurrency, Distributed and Fault tolerant
  • 3. Data Types/Structures 1 # integer 2.0 # float true # boolean :atom # atom / symbol 'elixir' # character list "elixir" # string [1, 2, 3] # list {1,2} # tuple [{:a, 1}, {:b, 2}] # keyword list [a: 1, b: 2] # ^ same keyword list %{a: 1, b: 2, c: 3} # hash
  • 4. Pattern Matching a = 1 {x, y} = {0, 0} [head | tail] = [1, 2, 3] result = case {1, 2, 3} do {4, 5, 6} -> "Doesn't match" {1, x, 3} when x > 3 -> "doesn't match because 2 < 3" {x, 2, 3} -> "matches and x is #{x}" _ -> "matches if nothing above matches" end def zero?(0), do: true def zero?(x) when is_number(x), do: false
  • 5. Modules defmodule Math do def sum(a, b) do a + b end def sub(a, b) do a - b end end IO.puts (Math.sum(3,4))
  • 6. Structs defmodule Person do defstruct name: "Sattar", age: 40 end me = %Person{name: "AbdulSattar"} IO.puts me.name # Abdulsattar %Person{name: name, age: age} = me IO.puts(age) # 40 youngMe = %{me | age: 10}
  • 7. Protocols defprotocol Blank do @doc "Returns true if data is considered blank/empty" def blank?(data) end defimpl Blank, for: Integer do def blank?(0), do: true def blank?(_), do: false end defimpl Blank, for: List do def blank?([]), do: true def blank?(_), do: false end Blank.blank?(3) # false Blank.blank?([]) # true
  • 8. Enumerables iex(2)> Enum.map([1, 2, 3], fn x -> x * x end) [1, 4, 9] iex(3)> Enum.map([1, 2, 3], &(&1 * &1)) [1, 4, 9] iex(4)> Enum.reduce(1..100, 0, &+/2) 5050
  • 9. Pipe Operator sumOfSquares = Enum.reduce(Enum.map(1..100, fn x -> x * x end), 0, &+/2) sumOfSquares1 = 1..100 |> Enum.map(fn x -> x * x end) |> Enum.reduce(0, &+/2) square = fn x -> x * x end sumOfSquares2 = 1..100 |> Enum.map(square) |> Enum.sum
  • 10. Macros defmodule Unless do defmacro macro_unless(clause, expression) do quote do if(!unquote(clause), do: unquote(expression)) end end end Unless.macro_unless false, do: IO.puts "prints" Unless.macro_unless true, do: IO.puts "doesn't print"
  • 11. Processes pid = spawn fn -> receive do msg -> IO.puts "Received: #{msg}" end end send pid, "Hello!" send pid, "3 times"