Intro

What is Elixir?
- Elixir is a dynamic programming language built on top of the Erlang VM...it compiles to Erlang byte code
- Syntactically it is a bit different from Erlang, sharing similarities with other languages, such as Ruby
- It is a functional programming language
Why Elixir?
- While relatively new, being that's it built on Erlang (around since the '80s), it's been battle-tested
- Concurrency
- Functional and immutability
- It's own package management system (Hex: https://hex.pm/)
- An easy to use build tool (Mix)
- Popularity is growing....i.e. more users and support
Concurrency
- Lightweight processes can be spun up with ease
- each one gets a pid
- utilizes Erlang scheduler
- Programs can be deployed as sets of processes
- Pass messages
# Define a module
defmodule Messenger do
def ping do
receive do
msg -> IO.puts("Received #{msg}")
# Invoke it here recursively to keep it up
ping()
end
end
end
# Create a process with spawn/3
my_pid = spawn(Messenger, :ping, [])
# Send a message
send(my_pid, "Hello")
Functional
- Immutability makes programs easier to reason and can prevent issues with concurrency
- Example, using pipeline operator, makes composing chained functions simple
# Example of function using the pipeline operator (|>)
"HelloWorld" |> String.upcase |> String.split_at(5) |> Tuple.to_list |> List.last
## WORLDFurther Resources
Web Framework
Phoenix
Intro Elixir
By ralucas
Intro Elixir
- 330