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

Elixir Sightseeing Tour

Elixir Sightseeing Tour

Andrea Leopardi

September 26, 2019
Tweet

More Decks by Andrea Leopardi

Other Decks in Programming

Transcript

  1. case some_expression do 1 -> "it's one!" {_, _} ->

    "it's a 2-elem tuple!" _other -> "it's something else" end
  2. send(dest_pid, {self(), {:add, 1, 7}}) receive do {:add_response, response} ->

    IO.puts("Response: #{response}") after 1000 -> IO.puts("Timeout :(") end
  3. ref = Process.monitor(dest_pid) send(dest_pid, {self(), {:add, 1, 7}}) receive do

    {:add_response, response} -> IO.puts("Response: #{response}") {:DOWN, ^ref, _, _, _} -> IO.puts("Process went down") after 1000 -> IO.puts("Timeout :(") end
  4. two_code = quote do 1 + 1 end quote do

    add(1, unquote(two_code)) end
  5. if condition do expression end quote do case unquote(condition) do

    true -> unquote(expression) false -> nil end end