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

Say Hello to Elixir

Say Hello to Elixir

Presented at The Guild on Feb 27th, 2014, this is a look at Elixir, how it works, and what we can learn from its concepts and philosophy in our everyday object-oriented programming.

Arjan van der Gaag

February 27, 2014
Tweet

More Decks by Arjan van der Gaag

Other Decks in Programming

Transcript

  1. – erlang.org Erlang is a programming language used to build

    massively scalable soft real-time systems with requirements on high availability. Erlang's runtime system has built-in support for concurrency, distribution and fault tolerance.
  2. Anonymous functions iex> Enum.map [1, 2, 3], fn n ->

    n * 2 end [2, 4, 6] iex> Enum.map [1, 2, 3], &(&1 * 2) [2, 4, 6]
  3. Named functions & modules defmodule Greeter do def greet(name) do

    IO.puts "Hello, #{name}" end end iex> Greeter.greet("James") "Hello, James" iex> Enum.each ["john", “paul”], &Greeter.greet/1 "Hello, john" "Hello, paul"
  4. defmodule MyMap do ! ! ! ! ! end Pattern

    matching ! def map([], _), do: [] ! ! ! def map([head | tail], fun) do [fun.(head) | map(tail, fun)] end
  5. Assert defmodule TruthTest do use ExUnit.Case test "considers two strings

    equal" do assert "foo" == "bar" end end ! ! ! ! ! ! ! ! 1) test considers two strings equal (TruthTest) ** (ExUnit.ExpectationError) expected: "foo" to be equal to (==): "bar" at test/demo/truth_test.exs:5
  6. Actors fib = spawn(Fibonacci, :server, [self]) fib <- { :number,

    17 } ! ! ! receive do ! ! ! ! ! ! end ! ! ! ! { :ok, result } -> IO.puts "Received response:" IO.puts result ! ! ! ! ! ! ! { _, error } -> IO.puts “An error occured!” IO.puts error
  7. Find out more • elixir-lang.org • erlang.org • Programming Elixir

    (Dave Thomas) • Meet Elixir (Peepcode play-by-play with José Valim) • exercism.io • Gary Bernhardt: Boundaries