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

A Brief Introduction to Elixir

A Brief Introduction to Elixir

Lightning talk presented in DaWanda

Avatar for Iuri Fernandes

Iuri Fernandes

March 11, 2016
Tweet

More Decks by Iuri Fernandes

Other Decks in Technology

Transcript

  1. OTP • Framework • Concurrent and distributed applications • Models

    behaviors for processes • And much more …
  2. OTP Examples Image from “Learn you some Erlang for great

    good” licensed under Creative Commons
  3. Elixir • Created in 2012 by José Valim • Functional

    (Immutability) • Dynamically typed • Metaprogramming • Fresh life to Erlang ecosystem • BEAM VM
  4. Drops of Elixir defmodule MyModule do def increment(argument) do argument

    + 1 end end defmodule PatternMatching do def head([]), do: nil def head([head | _]), do: head end
  5. Drops of Elixir defmodule MyModule do def increment(x) when is_integer(x)

    do x + 1 end end defmodule PatternMatching do def head([]), do: nil def head([head | _]), do: head end
  6. Drops of Elixir parent = self() # Spawns an Elixir

    process (not an operating system one!) spawn_link(fn -> send parent, {:msg, "hello world"} end) # Block until the message is received receive do {:msg, contents} -> IO.puts contents end
  7. Drops of Elixir defmodule Stack do use GenServer # Callbacks

    def handle_call(:pop, _from, [h|t]) do {:reply, h, t} end def handle_cast({:push, item}, state) do {:noreply, [item|state]} end end
  8. Drops of Elixir # Start the server {:ok, pid} =

    GenServer.start_link(Stack, [:hello]) # This is the client GenServer.call(pid, :pop) #=> :hello GenServer.cast(pid, {:push, :world}) #=> :ok GenServer.call(pid, :pop) #=> :world
  9. Applications • Chat web app with Phoenix • Embedded systems

    with Nerves • Pusher app replacement with Poxa