Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Un traguito de Elixir

Un traguito de Elixir

Introduction to Elixir

Talk given at Unotalks meetup on January10th 2018

Fernando Perales

January 10, 2018
Tweet

More Decks by Fernando Perales

Other Decks in Programming

Transcript

  1. Fernando Perales Senior Software Engineer @ michelada.io Ing. En Computación

    @ UdeG (CUCEI) Anfitrión @ RubyGDL Co-fundador @ RailsBridge México Instructor de Ruby on Rails @ Platzi Estudiante de Alemán y Bajo Eléctrico Fan de Gregory Sallust
  2. ¿Qué es Erlang? Creado en 1986 por la compañía Ericsson

    Para realizar aplicaciones distribuidas, tolerantes a fallos, soft-real-time y de funcionamiento ininterrumpido
  3. Erlang en números La máquina virtual de Erlang (BEAM) es

    desarrollada por Joe Armstrong, Robert Virding y Mike Williams en 1985
  4. Erlang en números El primer sistema en producción fue el

    Switch AXD301 con 1 MLOC y disponibilidad de 9 nueves
  5. Erlang en números Más del 50% del tráfico de Internet

    pasa por sistemas construídos con Erlang
  6. ¿Qué es Elixir? Lenguaje de programación funcional, concurrente, de propósito

    general que se ejecuta sobre la máquina virtual de Erlang (BEAM)
  7. ¿Qué es Elixir? Elixir fue creado en el 2011 por

    José Valim. Un contribuidor de Ruby por bastantes años que buscaba cómo mejorar el desempeño del lenguaje para aprovechar múltiples CPUs
  8. ¿Qué es Elixir? Mientras la BEAM resolvía era perfecta para

    el tipo de problemas que buscaba resolver, sentía que al lenguaje le faltaban características que otros lenguajes sí tenian
  9. Ventajas que Elixir aporta No hay costo de conversión al

    usar código de Erlang en Elixir y viceversa
  10. Tipos básicos: enteros iex> decimal = 1000 1000 iex> -5

    -5 iex> hex = 0xabcd 43981 iex> bin = 0b1100 12 jeregrine.github.io/elixir-by-example
  11. Tipos básicos: flotantes iex> 4.0 4.0 iex> 0.567 0.567 iex>

    0.567e2 56.7 iex> 0.567e-2 0.00567 jeregrine.github.io/elixir-by-example
  12. Tipos básicos: booleanos iex> true true iex> true == true

    true iex> true == false false jeregrine.github.io/elixir-by-example
  13. Tipos básicos: átomos iex> :stuff :stuff iex> :stuff == :stuff

    true iex> :+ :+ jeregrine.github.io/elixir-by-example
  14. Tipos básicos: binarios iex> <<1, 2, 3>> <<1, 2, 3>>

    iex> size <<1, 2, 3>> 3 jeregrine.github.io/elixir-by-example
  15. Cadenas y listas de caracteres iex> name = "Paul" "Paul"

    iex> "Hello #{name}!" "Hello Paul!" jeregrine.github.io/elixir-by-example
  16. Cadenas y listas de caracteres iex> 'hello' 'hello' iex> is_binary

    'hello' false iex> is_list 'hello' true jeregrine.github.io/elixir-by-example
  17. Rangos iex> 1..3 1..3 iex> Enum.map 1..3, fn num ->

    num * 2 end [2, 4, 6] jeregrine.github.io/elixir-by-example
  18. Tuplas iex> {stuff, num, _} = {:stuff, 1, "things"} {:stuff,

    1, "things"} iex> stuff :stuff iex> num 1 jeregrine.github.io/elixir-by-example
  19. Tuplas i e x > { s t a t

    u s , h a n d l e } = File.open("example.txt") {:ok, #PID<0.43.0>} jeregrine.github.io/elixir-by-example
  20. Tuplas iex> {:ok, handle} = File.open("doesntexist.txt") ** (MatchError) no match

    of right hand side value: {:error, :enoent} jeregrine.github.io/elixir-by-example
  21. Listas iex> [1, 2, 3] [1, 2, 3] iex> [:stuff,

    1, "things"] [:stuff, 2, "things"] jeregrine.github.io/elixir-by-example
  22. Listas iex> [_, two, _] = [1, 2, 3] [1,

    2, 3] iex> two 2 iex> [head | tail] = [1, 2, 3, 4] [1, 2, 3, 4] iex> head 1 iex> tail [2, 3, 4] jeregrine.github.io/elixir-by-example
  23. Listas iex> List.flatten [1, [2, 3], 4] [1, 2, 3,

    4] iex> List.zip [[1, 2, 3], [4, 5, 6]] [{1, 4}, {2, 5}, {3, 6}] iex> List.foldl [1, 2, 3], 0, fn num, acc -> num + acc end 6 jeregrine.github.io/elixir-by-example
  24. Keyword list iex> [head | tail] = [a: 1, b:

    2] [a: 1, b: 2] iex> head {:a, 1} iex> Keywords.get [a: 1, b: 2], :a 1 iex> Keywords.get_values [a: 1, b: 2] [1, 2] jeregrine.github.io/elixir-by-example