SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
Introducción a Elixir
Svet Ivantchev

5 de marzo de 2019
CPUs en los últimas décadas
Ref: https://github.com/karlrupp/microprocessor-trend-data/tree/master/42yrs
Functional programming
En ciencias de la computación, la programación funcional es un
paradigma de programación declarativa basado en el uso de
funciones matemáticas, en contraste con la programación
imperativa, que enfatiza los cambios de estado mediante la
mutación de variables.
https://es.wikipedia.org/wiki/Programación_funcional
Functional programming 2
El bloque básico son las funciones, los valores
no cambian y el código es (principalmente) declarativo.
OOP: Objetos manipulados a través de métodos
FP: Estructuras de datos manipulados a través de funciones
JavaScript vs Elixir
var list = ["dogs", "hot dogs", "bananas"];
function upcase(list) {

var newList = [];

for (var i = 0; i < list.length; i++) {
newList.push(list[i].toUpperCase());
}
return newList; }
upcase(list);
// => ["DOGS", "HOT DOGS", "BANANAS"]
defmodule StringList do

def upcase([]), do: []

def upcase([first | rest]), do: [String.upcase(first) | upcase(rest)]
end
StringList.upcase(["dogs", "hot dogs", "bananas"])
# => ["DOGS", "HOT DOGS", "BANANAS"]
Introducción a Elixir
Remember UniEE 2009
Introducción a Elixir
Introducción a Elixir
Qué tiene de especial Erlang (y Elixir)?
• Tolerancia a fallos
• Hot upgrades
• Procesos "ligeros"
• Networking integrado
• Integrado soporte para paralelizar
• Garbage collector
• Tail recursion
• Pattern matching
Elixir 101
$ iex
Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:4:4] ...
Interactive Elixir (1.7.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 1+4
5
iex(2)> 123*5
615
iex(3)> 3/2
1.5
iex(4)> 0b111+1
8
iex(7)> 0xA+1
11
iex(8)> 1==2
false
iex(9)> 3==3
true
strings, atoms, anonymous functions
iex(10)> "hello " <> "world"
"hello world"
iex(11)> :atom
:atom
iex(13)> doble = fn x -> 2*x end
#Function<6.128620087/1 in :erl_eval.expr/5>
iex(14)> doble.(12)
24
iex(15)> is_atom(:hola)
true
iex(16)> is_function(doble)
true
iex(17)> is_function(doble,1)
true
iex(18)> is_function(doble,2)
false
iex(21)> cu = fn x -> doble.(x)*2 end
#Function<6.128620087/1 in :erl_eval.expr/5>
iex(23)> cu.(12)
48
listas
iex(32)> [4, 5, 42]
[4, 5, 42]
iex(33)> [4, 5, 42, :eibar, 33, true]
[4, 5, 42, :eibar, 33, true]
iex(35)> length([4, 5, 42, :eibar, 33, true])
6
iex(36)> length [4, 5, 42, :eibar, 33, true]
6
iex(37)> l1 = [1, 2, 3, 4, 10]
[1, 2, 3, 4, 10]
iex(38)> hd(l1)
1
iex(39)> tl(l1)
[2, 3, 4, 10]
iex(46)> l1 ++ [44, 55]
[1, 2, 3, 4, 10, 44, 55]
iex(103)> l1 -- [4]
[1, 2, 3, 10]
tuples
iex(60)> t1 = {:ok, "hoy"}
{:ok, "hoy"}
iex(61)> elem(t1, 0)
:ok
iex(62)> put_elem(t1, 1, "nuevo")
{:ok, "nuevo"}
pattern matching
iex(68)> x = 42
42
iex(69)> 42 = x
42
iex(70)> 1 = x
** (MatchError) no match of right hand side value: 42
iex(72)> {a, b, c} = {:hello, "Ermua", 55}
{:hello, "Ermua", 55}
iex(73)> a
:hello
iex(74)> b
"Ermua"
iex(76)> {a, b, c} = {:hello, "Ermua"}
** (MatchError) no match of right hand side value: {:hello, "Ermua"}
iex(94)> [a, b, c] = [5, 6, 7]
[5, 6, 7]
iex(95)> b
6
iex(96)> [h | t] = [3, 4, 5, 6]
[3, 4, 5, 6]
iex(97)> h
3
iex(98)> t
[4, 5, 6]
case
case {1, 2, 3} do
{4, 5, 6} ->
"Esto no pasa nunca, no hay match"
{1, x, 3} ->
"Aquí el x tendrá valor 3"
_ ->
"Esto esta match-edado siempre"
end
modules and functions
defmodule Math do
def sum(a, b) do
do_sum(a, b)
end
defp do_sum(a, b) do
a + b
end
end
IO.puts Math.sum(1, 2) #=> 3
IO.puts Math.do_sum(1, 2) #=> ** (UndefinedFunctionError)
Pattern matching en argumentos
defmodule Talker do
  def say_hello("Bob"), do: "Hello, Bob!"
  def say_hello("Jon"), do: "Hi there, Jon!"
  def say_hello(name) do
   "Hi, #{name}."
  end
end
defmodule Talker do
 def say_hello(nil), do: "Please give me a name"
 def say_hello(name) do
   "Hi, #{name}."
 end
end
recursion por todas partes
defmodule Math do
def double_each([head | tail]) do
[head * 2 | double_each(tail)]
end
def double_each([]) do
[]
end
end
iex> Math.double_each([1, 2, 3]) #=> [2, 4, 6]
defmodule Math do
def sum_list([head | tail], accumulator) do
sum_list(tail, head + accumulator)
end
def sum_list([], accumulator) do
accumulator
end
end
iex> Math.sum_list([1, 2, 3], 0) #=> 6
Máquina virtual de Erlang (BEAM) y procesos
iex(111)> pid = spawn fn -> 42*2 end
#PID<0.220.0>
iex(112)> Process.alive?(pid)
false
iex(116)> self()
#PID<0.101.0>
iex(117)> Process.alive?(self())
true
iex(120)> self |> Process.alive?
true
Ref: img de https://speakerdeck.com/sasajuric
Ref: img de https://speakerdeck.com/sasajuric
Monte Carlo y pi
defmodule MonteCarlo do
def pi(n) do
count = Enum.count(1..n, fn _ ->
x = :rand.uniform
y = :rand.uniform
:math.sqrt(x*x + y*y) <= 1
end)
pi = 4 * count / n
IO.puts "Iteraciones: #{n}, valor de pi: #{pi}"
end
end
iex(59)> spawn fn -> MonteCarlo.pi(10_000) end
#PID<0.6145.0>
Iterations: 10000, pi value: 3.158
Nota: lanzar múltiples procesos y observar htop y :observer
iex(2)> :observer.start
Ref: http://bob.ippoli.to/haskell-for-erlangers-2014/#/cost-of-concurrency
Múltiples nodos
$ iex --sname eibar
Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Interactive Elixir (1.7.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(eibar@svet13)1> defmodule Hello do
...(eibar@svet13)1> def world, do: IO.puts "Hello from Eibar"
...(eibar@svet13)1> end
iex(eibar@svet13)3> Hello.world()
Hello from Eibar
:ok
$ iex --sname ermua
Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Interactive Elixir (1.7.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(ermua@svet13)1>
nil
iex(ermua@svet13)2> Hello.world()
** (UndefinedFunctionError) function Hello.world/0 is undefined
iex(ermua@svet13)2> Node.spawn :eibar@svet13, fn -> Hello.world end
Hello from Eibar
#PID<10586.120.0>
Lo que no esta aquí
• message passing
• mix
• supervisor
• erlang OTP
• releases and hot reloading
• doctests
• mucho más ...
Permutaciones
123 -> 123 132 213 231 312 321
1234 -> 1234 1243 1324 1342 1423 1432 2134 2143
2314 2341 2413 2431 3124 3142 3214 3241
3412 3421 4123 4132 4213 4231 4312 4321
https://rosettacode.org/wiki/Permutations
Permutaciones
Para ver todas las permutaciones de X123:
1- calcular las de de 123: 123, 132, 213, 231, 312, 321
2- Intercalar X: X123, 1X23, 12X3, 123X

123 -> 123 132 213 231 312 321
1234 -> 1234 1243 1324 1342 1423 1432 2134 2143
2314 2341 2413 2431 3124 3142 3214 3241
3412 3421 4123 4132 4213 4231 4312 4321
Permutaciones en Elixir
defmodule Comb do
def permute([]), do: [[]]
def permute(list) do
for x <- list, y <- permute(list -- [x]), do: [x|y]
end
end
iex> Comb.permute []
[[]]
iex> Comb.permute [1]
[[1]]
iex> Comb.permute [1,2]
[[1, 2], [2, 1]]
iex> Comb.permute [1,2,3]
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
> Comb.permute ['e','i','b','a','r']
[
['e', 'i', 'b', 'a', 'r'],
['e', 'i', 'b', 'r', 'a'],
....
Idea de metaprogramming
Programas que escriben programas
Un programa el Elixir se puede representar con
estructuras de datos del propio lenguaje
Idea de metaprogramming in Elixir, AST
iex(127)> quote do: sum(4,5)
{:sum, [], [4, 5]}
iex(129)> quote do: 5+6
{:+, [context: Elixir, import: Kernel], [5, 6]}
iex(146)> quote do: sum(4, 2*(5+6), 5)
{:sum, [],
[
4,
{:*, [context: Elixir, import: Kernel],
[2, {:+, [context: Elixir, import: Kernel], [5, 6]}]},
5
]}
Y en "la vida real"?
Phoenix: proyecto nuevo
$ mix phx.new hello_phoenix
* creating hello_phoenix/config/config.exs
* creating hello_phoenix/config/dev.exs
* creating hello_phoenix/config/prod.exs]
* ...
* We are almost there! The following steps are missing:
* $ cd hello_phoenix
* Then configure your database in config/dev.exs and run:
* $ mix ecto.create
* Start your Phoenix app with:
* $ mix phx.server
* You can also run your app inside IEx (Interactive Elixir) as:
* $ iex -S mix phx.server
Phoenix: iniciar
$ mix ecto.create
Compiling 13 files (.ex)
Generated hello_phoenix app
The database for HelloPhoenix.Repo has been created
$ mix phx.server
[info] Running HelloPhoenixWeb.Endpoint with cowboy 2.6.1 at http://
localhost:4000
Phoenix: live reload, channels
$ vi ./lib/hello_phoenix_web/templates/page/index.html.eex
Embedded hardware
mix firmware.burn -- SD completa en 2 seg
cd hello_nerves
MIX_TARGET=rpi3 mix deps.get
mix nerves.release.init
mix firmware
mix firmware.burn
Building /Users/svet/nerves/hello_nerves/_build/rpi3/dev/nerves/images/hello_nerves.fw...
Use 29.72 GiB memory card found at /dev/rdisk3? [Yn]
|====================================| 100% (28.77 / 28.77) MB
Success!
Elapsed time: 1.988 s
Elixir, Erlang ... ¿eso lo usa alguien?
Elixir, Erlang ... ¿eso lo usa alguien?
Ref: https://kyan.com/news/an-introduction-to-the-elixir-programming-language

Contenu connexe

Tendances

Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptLoïc Knuchel
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей КоваленкоFwdays
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheetGil Cohen
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)David de Boer
 
Exploring slides
Exploring slidesExploring slides
Exploring slidesakaptur
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collectionsMyeongin Woo
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxEleanor McHugh
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with goEleanor McHugh
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanWei-Yuan Chang
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programmingChiwon Song
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...akaptur
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonChristoph Matthies
 

Tendances (20)

Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScript
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)
 
Intro
IntroIntro
Intro
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Don't do this
Don't do thisDon't do this
Don't do this
 
Talk Code
Talk CodeTalk Code
Talk Code
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collections
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with go
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programming
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in Python
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
Python bokeh cheat_sheet
Python bokeh cheat_sheet Python bokeh cheat_sheet
Python bokeh cheat_sheet
 

Similaire à Introducción a Elixir

TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcionaltdc-globalcode
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnArnaud Joly
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Python profiling
Python profilingPython profiling
Python profilingdreampuf
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingEelco Visser
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingSaurabh Singh
 
sonam Kumari python.ppt
sonam Kumari python.pptsonam Kumari python.ppt
sonam Kumari python.pptssuserd64918
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in rubyKoen Handekyn
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cythonAnderson Dantas
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQIntro C# Book
 
Yurii Bodarev - Ecto DSL
Yurii Bodarev - Ecto DSLYurii Bodarev - Ecto DSL
Yurii Bodarev - Ecto DSLElixir Club
 
Ecto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii BodarevEcto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii BodarevElixir Club
 

Similaire à Introducción a Elixir (20)

TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcional
 
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
 
Elixir and OTP Apps introduction
Elixir and OTP Apps introductionElixir and OTP Apps introduction
Elixir and OTP Apps introduction
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Python profiling
Python profilingPython profiling
Python profiling
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
sonam Kumari python.ppt
sonam Kumari python.pptsonam Kumari python.ppt
sonam Kumari python.ppt
 
Javascript
JavascriptJavascript
Javascript
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in ruby
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
 
Monadologie
MonadologieMonadologie
Monadologie
 
Python Training
Python TrainingPython Training
Python Training
 
Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQ
 
Yurii Bodarev - Ecto DSL
Yurii Bodarev - Ecto DSLYurii Bodarev - Ecto DSL
Yurii Bodarev - Ecto DSL
 
Ecto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii BodarevEcto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii Bodarev
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 

Plus de Svet Ivantchev

Machne Learning and Human Learning (2013).
Machne Learning and Human Learning (2013).Machne Learning and Human Learning (2013).
Machne Learning and Human Learning (2013).Svet Ivantchev
 
Big Data: 
Some Questions in its Use in Applied Economics (2017)
Big Data: 
Some Questions in its Use in Applied Economics (2017)Big Data: 
Some Questions in its Use in Applied Economics (2017)
Big Data: 
Some Questions in its Use in Applied Economics (2017)Svet Ivantchev
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Svet Ivantchev
 
Gaztea Tech 2015: 4. GT Drawbot Control
Gaztea Tech 2015: 4. GT Drawbot ControlGaztea Tech 2015: 4. GT Drawbot Control
Gaztea Tech 2015: 4. GT Drawbot ControlSvet Ivantchev
 
Gaztea Tech 2015: 3. Processing y Firmata
Gaztea Tech 2015: 3. Processing y FirmataGaztea Tech 2015: 3. Processing y Firmata
Gaztea Tech 2015: 3. Processing y FirmataSvet Ivantchev
 
Gaztea Tech 2015: 2. El GT DrawBot
Gaztea Tech 2015: 2. El GT DrawBotGaztea Tech 2015: 2. El GT DrawBot
Gaztea Tech 2015: 2. El GT DrawBotSvet Ivantchev
 
Gaztea Tech 2015: 1. Introducción al Arduino
Gaztea Tech 2015: 1. Introducción al ArduinoGaztea Tech 2015: 1. Introducción al Arduino
Gaztea Tech 2015: 1. Introducción al ArduinoSvet Ivantchev
 
Learning Analytics and Online Learning: New Oportunities?
Learning Analytics and Online Learning: New Oportunities?Learning Analytics and Online Learning: New Oportunities?
Learning Analytics and Online Learning: New Oportunities?Svet Ivantchev
 
How Machine Learning and Big Data can Help Us with the Human Learning
How Machine Learning and Big Data can Help Us with the Human LearningHow Machine Learning and Big Data can Help Us with the Human Learning
How Machine Learning and Big Data can Help Us with the Human LearningSvet Ivantchev
 
Libros electrónicos IV: ePub 2
Libros electrónicos IV: ePub 2Libros electrónicos IV: ePub 2
Libros electrónicos IV: ePub 2Svet Ivantchev
 
Libros electrónicos III
Libros electrónicos IIILibros electrónicos III
Libros electrónicos IIISvet Ivantchev
 
Libros electrónicos II - ePub
Libros electrónicos II - ePubLibros electrónicos II - ePub
Libros electrónicos II - ePubSvet Ivantchev
 
Libros electrónicos I
Libros electrónicos ILibros electrónicos I
Libros electrónicos ISvet Ivantchev
 
Cloud Computing: Just Do It
Cloud Computing: Just Do ItCloud Computing: Just Do It
Cloud Computing: Just Do ItSvet Ivantchev
 
Cloud Computing: What it is, DOs and DON'Ts
Cloud Computing: What it is, DOs and DON'TsCloud Computing: What it is, DOs and DON'Ts
Cloud Computing: What it is, DOs and DON'TsSvet Ivantchev
 
Los mitos de la innovación
Los mitos de la innovaciónLos mitos de la innovación
Los mitos de la innovaciónSvet Ivantchev
 

Plus de Svet Ivantchev (20)

Machne Learning and Human Learning (2013).
Machne Learning and Human Learning (2013).Machne Learning and Human Learning (2013).
Machne Learning and Human Learning (2013).
 
Big Data: 
Some Questions in its Use in Applied Economics (2017)
Big Data: 
Some Questions in its Use in Applied Economics (2017)Big Data: 
Some Questions in its Use in Applied Economics (2017)
Big Data: 
Some Questions in its Use in Applied Economics (2017)
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
Gaztea Tech 2015: 4. GT Drawbot Control
Gaztea Tech 2015: 4. GT Drawbot ControlGaztea Tech 2015: 4. GT Drawbot Control
Gaztea Tech 2015: 4. GT Drawbot Control
 
Gaztea Tech 2015: 3. Processing y Firmata
Gaztea Tech 2015: 3. Processing y FirmataGaztea Tech 2015: 3. Processing y Firmata
Gaztea Tech 2015: 3. Processing y Firmata
 
Gaztea Tech 2015: 2. El GT DrawBot
Gaztea Tech 2015: 2. El GT DrawBotGaztea Tech 2015: 2. El GT DrawBot
Gaztea Tech 2015: 2. El GT DrawBot
 
Gaztea Tech 2015: 1. Introducción al Arduino
Gaztea Tech 2015: 1. Introducción al ArduinoGaztea Tech 2015: 1. Introducción al Arduino
Gaztea Tech 2015: 1. Introducción al Arduino
 
Learning Analytics and Online Learning: New Oportunities?
Learning Analytics and Online Learning: New Oportunities?Learning Analytics and Online Learning: New Oportunities?
Learning Analytics and Online Learning: New Oportunities?
 
How Machine Learning and Big Data can Help Us with the Human Learning
How Machine Learning and Big Data can Help Us with the Human LearningHow Machine Learning and Big Data can Help Us with the Human Learning
How Machine Learning and Big Data can Help Us with the Human Learning
 
Vienen los Drones!
Vienen los Drones!Vienen los Drones!
Vienen los Drones!
 
Data Science
Data ScienceData Science
Data Science
 
Libros electrónicos IV: ePub 2
Libros electrónicos IV: ePub 2Libros electrónicos IV: ePub 2
Libros electrónicos IV: ePub 2
 
Libros electrónicos III
Libros electrónicos IIILibros electrónicos III
Libros electrónicos III
 
Libros electrónicos II - ePub
Libros electrónicos II - ePubLibros electrónicos II - ePub
Libros electrónicos II - ePub
 
Libros electrónicos I
Libros electrónicos ILibros electrónicos I
Libros electrónicos I
 
Cloud Computing: Just Do It
Cloud Computing: Just Do ItCloud Computing: Just Do It
Cloud Computing: Just Do It
 
Cloud Computing: What it is, DOs and DON'Ts
Cloud Computing: What it is, DOs and DON'TsCloud Computing: What it is, DOs and DON'Ts
Cloud Computing: What it is, DOs and DON'Ts
 
BigData
BigDataBigData
BigData
 
Los mitos de la innovación
Los mitos de la innovaciónLos mitos de la innovación
Los mitos de la innovación
 
eFaber en 5 minutos
eFaber en 5 minutoseFaber en 5 minutos
eFaber en 5 minutos
 

Dernier

KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServiceRenan Moreira de Oliveira
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIUdaiappa Ramachandran
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdfJamie (Taka) Wang
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
GenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncGenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncObject Automation
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?SANGHEE SHIN
 
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataCloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataSafe Software
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceMartin Humpolec
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 

Dernier (20)

KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
GenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation IncGenAI and AI GCC State of AI_Object Automation Inc
GenAI and AI GCC State of AI_Object Automation Inc
 
Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?
 
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataCloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your Salesforce
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 

Introducción a Elixir

  • 1. Introducción a Elixir Svet Ivantchev
 5 de marzo de 2019
  • 2. CPUs en los últimas décadas Ref: https://github.com/karlrupp/microprocessor-trend-data/tree/master/42yrs
  • 3. Functional programming En ciencias de la computación, la programación funcional es un paradigma de programación declarativa basado en el uso de funciones matemáticas, en contraste con la programación imperativa, que enfatiza los cambios de estado mediante la mutación de variables. https://es.wikipedia.org/wiki/Programación_funcional
  • 4. Functional programming 2 El bloque básico son las funciones, los valores no cambian y el código es (principalmente) declarativo. OOP: Objetos manipulados a través de métodos FP: Estructuras de datos manipulados a través de funciones
  • 5. JavaScript vs Elixir var list = ["dogs", "hot dogs", "bananas"]; function upcase(list) {
 var newList = [];
 for (var i = 0; i < list.length; i++) { newList.push(list[i].toUpperCase()); } return newList; } upcase(list); // => ["DOGS", "HOT DOGS", "BANANAS"] defmodule StringList do
 def upcase([]), do: []
 def upcase([first | rest]), do: [String.upcase(first) | upcase(rest)] end StringList.upcase(["dogs", "hot dogs", "bananas"]) # => ["DOGS", "HOT DOGS", "BANANAS"]
  • 10. Qué tiene de especial Erlang (y Elixir)? • Tolerancia a fallos • Hot upgrades • Procesos "ligeros" • Networking integrado • Integrado soporte para paralelizar • Garbage collector • Tail recursion • Pattern matching
  • 11. Elixir 101 $ iex Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:4:4] ... Interactive Elixir (1.7.3) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> 1+4 5 iex(2)> 123*5 615 iex(3)> 3/2 1.5 iex(4)> 0b111+1 8 iex(7)> 0xA+1 11 iex(8)> 1==2 false iex(9)> 3==3 true
  • 12. strings, atoms, anonymous functions iex(10)> "hello " <> "world" "hello world" iex(11)> :atom :atom iex(13)> doble = fn x -> 2*x end #Function<6.128620087/1 in :erl_eval.expr/5> iex(14)> doble.(12) 24 iex(15)> is_atom(:hola) true iex(16)> is_function(doble) true iex(17)> is_function(doble,1) true iex(18)> is_function(doble,2) false iex(21)> cu = fn x -> doble.(x)*2 end #Function<6.128620087/1 in :erl_eval.expr/5> iex(23)> cu.(12) 48
  • 13. listas iex(32)> [4, 5, 42] [4, 5, 42] iex(33)> [4, 5, 42, :eibar, 33, true] [4, 5, 42, :eibar, 33, true] iex(35)> length([4, 5, 42, :eibar, 33, true]) 6 iex(36)> length [4, 5, 42, :eibar, 33, true] 6 iex(37)> l1 = [1, 2, 3, 4, 10] [1, 2, 3, 4, 10] iex(38)> hd(l1) 1 iex(39)> tl(l1) [2, 3, 4, 10] iex(46)> l1 ++ [44, 55] [1, 2, 3, 4, 10, 44, 55] iex(103)> l1 -- [4] [1, 2, 3, 10]
  • 14. tuples iex(60)> t1 = {:ok, "hoy"} {:ok, "hoy"} iex(61)> elem(t1, 0) :ok iex(62)> put_elem(t1, 1, "nuevo") {:ok, "nuevo"}
  • 15. pattern matching iex(68)> x = 42 42 iex(69)> 42 = x 42 iex(70)> 1 = x ** (MatchError) no match of right hand side value: 42 iex(72)> {a, b, c} = {:hello, "Ermua", 55} {:hello, "Ermua", 55} iex(73)> a :hello iex(74)> b "Ermua" iex(76)> {a, b, c} = {:hello, "Ermua"} ** (MatchError) no match of right hand side value: {:hello, "Ermua"} iex(94)> [a, b, c] = [5, 6, 7] [5, 6, 7] iex(95)> b 6 iex(96)> [h | t] = [3, 4, 5, 6] [3, 4, 5, 6] iex(97)> h 3 iex(98)> t [4, 5, 6]
  • 16. case case {1, 2, 3} do {4, 5, 6} -> "Esto no pasa nunca, no hay match" {1, x, 3} -> "Aquí el x tendrá valor 3" _ -> "Esto esta match-edado siempre" end
  • 17. modules and functions defmodule Math do def sum(a, b) do do_sum(a, b) end defp do_sum(a, b) do a + b end end IO.puts Math.sum(1, 2) #=> 3 IO.puts Math.do_sum(1, 2) #=> ** (UndefinedFunctionError)
  • 18. Pattern matching en argumentos defmodule Talker do   def say_hello("Bob"), do: "Hello, Bob!"   def say_hello("Jon"), do: "Hi there, Jon!"   def say_hello(name) do    "Hi, #{name}."   end end defmodule Talker do  def say_hello(nil), do: "Please give me a name"  def say_hello(name) do    "Hi, #{name}."  end end
  • 19. recursion por todas partes defmodule Math do def double_each([head | tail]) do [head * 2 | double_each(tail)] end def double_each([]) do [] end end iex> Math.double_each([1, 2, 3]) #=> [2, 4, 6] defmodule Math do def sum_list([head | tail], accumulator) do sum_list(tail, head + accumulator) end def sum_list([], accumulator) do accumulator end end iex> Math.sum_list([1, 2, 3], 0) #=> 6
  • 20. Máquina virtual de Erlang (BEAM) y procesos iex(111)> pid = spawn fn -> 42*2 end #PID<0.220.0> iex(112)> Process.alive?(pid) false iex(116)> self() #PID<0.101.0> iex(117)> Process.alive?(self()) true iex(120)> self |> Process.alive? true Ref: img de https://speakerdeck.com/sasajuric
  • 21. Ref: img de https://speakerdeck.com/sasajuric
  • 22. Monte Carlo y pi defmodule MonteCarlo do def pi(n) do count = Enum.count(1..n, fn _ -> x = :rand.uniform y = :rand.uniform :math.sqrt(x*x + y*y) <= 1 end) pi = 4 * count / n IO.puts "Iteraciones: #{n}, valor de pi: #{pi}" end end iex(59)> spawn fn -> MonteCarlo.pi(10_000) end #PID<0.6145.0> Iterations: 10000, pi value: 3.158 Nota: lanzar múltiples procesos y observar htop y :observer
  • 25. Múltiples nodos $ iex --sname eibar Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] Interactive Elixir (1.7.3) - press Ctrl+C to exit (type h() ENTER for help) iex(eibar@svet13)1> defmodule Hello do ...(eibar@svet13)1> def world, do: IO.puts "Hello from Eibar" ...(eibar@svet13)1> end iex(eibar@svet13)3> Hello.world() Hello from Eibar :ok $ iex --sname ermua Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] Interactive Elixir (1.7.3) - press Ctrl+C to exit (type h() ENTER for help) iex(ermua@svet13)1> nil iex(ermua@svet13)2> Hello.world() ** (UndefinedFunctionError) function Hello.world/0 is undefined iex(ermua@svet13)2> Node.spawn :eibar@svet13, fn -> Hello.world end Hello from Eibar #PID<10586.120.0>
  • 26. Lo que no esta aquí • message passing • mix • supervisor • erlang OTP • releases and hot reloading • doctests • mucho más ...
  • 27. Permutaciones 123 -> 123 132 213 231 312 321 1234 -> 1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321
  • 29. Permutaciones Para ver todas las permutaciones de X123: 1- calcular las de de 123: 123, 132, 213, 231, 312, 321 2- Intercalar X: X123, 1X23, 12X3, 123X
 123 -> 123 132 213 231 312 321 1234 -> 1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321
  • 30. Permutaciones en Elixir defmodule Comb do def permute([]), do: [[]] def permute(list) do for x <- list, y <- permute(list -- [x]), do: [x|y] end end iex> Comb.permute [] [[]] iex> Comb.permute [1] [[1]] iex> Comb.permute [1,2] [[1, 2], [2, 1]] iex> Comb.permute [1,2,3] [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] > Comb.permute ['e','i','b','a','r'] [ ['e', 'i', 'b', 'a', 'r'], ['e', 'i', 'b', 'r', 'a'], ....
  • 31. Idea de metaprogramming Programas que escriben programas Un programa el Elixir se puede representar con estructuras de datos del propio lenguaje
  • 32. Idea de metaprogramming in Elixir, AST iex(127)> quote do: sum(4,5) {:sum, [], [4, 5]} iex(129)> quote do: 5+6 {:+, [context: Elixir, import: Kernel], [5, 6]} iex(146)> quote do: sum(4, 2*(5+6), 5) {:sum, [], [ 4, {:*, [context: Elixir, import: Kernel], [2, {:+, [context: Elixir, import: Kernel], [5, 6]}]}, 5 ]}
  • 33. Y en "la vida real"?
  • 34. Phoenix: proyecto nuevo $ mix phx.new hello_phoenix * creating hello_phoenix/config/config.exs * creating hello_phoenix/config/dev.exs * creating hello_phoenix/config/prod.exs] * ... * We are almost there! The following steps are missing: * $ cd hello_phoenix * Then configure your database in config/dev.exs and run: * $ mix ecto.create * Start your Phoenix app with: * $ mix phx.server * You can also run your app inside IEx (Interactive Elixir) as: * $ iex -S mix phx.server
  • 35. Phoenix: iniciar $ mix ecto.create Compiling 13 files (.ex) Generated hello_phoenix app The database for HelloPhoenix.Repo has been created $ mix phx.server [info] Running HelloPhoenixWeb.Endpoint with cowboy 2.6.1 at http:// localhost:4000
  • 36. Phoenix: live reload, channels $ vi ./lib/hello_phoenix_web/templates/page/index.html.eex
  • 38. mix firmware.burn -- SD completa en 2 seg cd hello_nerves MIX_TARGET=rpi3 mix deps.get mix nerves.release.init mix firmware mix firmware.burn Building /Users/svet/nerves/hello_nerves/_build/rpi3/dev/nerves/images/hello_nerves.fw... Use 29.72 GiB memory card found at /dev/rdisk3? [Yn] |====================================| 100% (28.77 / 28.77) MB Success! Elapsed time: 1.988 s
  • 39. Elixir, Erlang ... ¿eso lo usa alguien?
  • 40. Elixir, Erlang ... ¿eso lo usa alguien? Ref: https://kyan.com/news/an-introduction-to-the-elixir-programming-language