elixir 5 minute intro
DESCRIPTION
Elixir is a new Ruby-like language on the Erlang VM.TRANSCRIPT
Best of Both WorldsBuilding Spaceships and staying Lean
-Doug Goldie
Lightning Talks, HackerDojo
Mountain View, CA, Nov 2014
19 Billion
465 Million
550
10
• Concurrency
• Distribution
• Fault Tolerant
• Soft real-time
• Hot code upgrade
• External interfaces
–Robert Virding, 2014
“Erlang is about building
Systems.”
+
defmodule Math do
def square(x) do
x * x
end
def sum(a, b) do
a + b + extra
end
defp extra do
5
end
end
defmodule Math do
def fact(0), do: 1
def fact(n), do: n * fact(n - 1)
end
defmodule Parallel do
def pmap(collection, func) do
collection
|> Enum.map(&(Task.async(fn -> func.(&1) end)))
|> Enum.map(&Task.await/1)
end
end
# We could run this function to get the squares
of the numbers from 1 to 1000.
# result = Parallel.pmap 1..1000, &(&1 * &1)
–Dave Thomas
“Combine Transformations with Pipelines.”
“Functions are Data Transformers.”
people = DB.find_customers
orders = Orders.for_customers(people)
tax = sales_tax(orders, 2013)
filing = prepare_filing(tax)
filing = prepare_filing(sales_tax(
Orders.for_customers(
DB.find_customers
)
)
)
filing = DB.find_customers
|> Orders.for_customers
|> sales_tax(2013)
|> prepare_filing
Macros• Code that writes code.
• Done at compile time.
• Domain Specific Languages (DSLs)
defmodule YourApp.Router do
use Phoenix.Router
scope alias: YourApp do
get "/pages/:page", PageController, :show
get "/files/*path", FileController, :show
resources "/users", UserController do
resources "/comments",CommentController
end
end
end
defp do_match("GET", "/page1", conn) do
...
end
defp do_match("POST", "/user", conn) do
...
end
+
=