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

Programação Funcional & Elixir

Amanda
November 04, 2017

Programação Funcional & Elixir

Amanda

November 04, 2017
Tweet

More Decks by Amanda

Other Decks in Technology

Transcript

  1. “Applications will increasingly need to be concurrent if they want

    to fully exploit continuing exponential CPU throughput gains.”
  2. Escalabilidade Tolerância a falhas Compatível com Erlang Hot Code Swap

    Linguagem Dinâmica Metaprogramação Polimorfismo Concorrência
  3. –Introduction to Functional Programming - Richard Bird Philip Wadler “Programming

    in a functional language consists of building definitions and using the computer to evaluate expressions.”
  4. Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h()

    ENTER for help) iex(1)> name = "Amanda" "Amanda" iex(2)> "Amanda" = name "Amanda" iex(3)> "Amanda S" = name ** (MatchError) no match of right hand side value: "Amanda"
  5. defmodule LightBulb do def switch(human, bulb) do ... end def

    switch(_) do IO.puts "Precisamos de um humano e de uma escada." end end
  6. defmodule LightBulb do def switch(human, bulb) when bulb.burned_out == true

    do ladder = Ladder.get_average_height() if ladder.under do … end end end
  7. new_bulb = Bulb.get_bulb() lader = Ladder.get_average_height() human = Human.climb(human, ladder)

    human = Human.remove_bulb(human, bulb) human = Human.put_bulb(human, new_bulb)
  8. defmodule NaturalNums do # Uma clausula para parar a recursão

    def print(1), do: IO.puts(1) def print(n) do # Imprime o número" IO.puts(n) # Chama a si mesmo com um valor a menos print(n - 1) end end