| Paradigm | multi-paradigm: functional, concurrent, distributed, process-oriented |
|---|---|
| First appeared | 2011; 9 years ago |
| Stable release | 1.10.3 / 25 April 2020; 43 days ago[1] |
| Typing discipline | dynamic, strong, duck |
| Platform | Erlang |
| License | Apache License 2.0[2] |
| Filename extensions | .ex, .exs |
| Website | elixir-lang |
| Influenced by | |
| Clojure, Erlang, Ruby | |
| Influenced | |
| LFE | |
Elixir is a functional, concurrent, general-purpose programming language that runs on the Erlang virtual machine (BEAM).[3] Elixir builds on top of Erlang and shares the same abstractions for building distributed, fault-tolerant applications. Elixir also provides productive tooling and an extensible design. The latter is supported by compile-time metaprogramming with macros and polymorphism via protocols.[4]
Elixir is used by companies such as PagerDuty,[5] Discord,[6] E-MetroTel,[7] Pinterest,[8] Moz,[9] Bleacher Report,[10] The Outline,[11] Inverse,[12] Divvy,[13] FarmBot[14] and for building embedded systems.[15][16] The community organizes yearly events in the United States,[17] Europe[18] and Japan[19] as well as minor local events and conferences.[20][21]
José Valim is the Brazilian creator of the Elixir programming language, a research and development project of Plataformatec. His goals were to enable higher extensibility and productivity in the Erlang VM while keeping compatibility with Erlang's ecosystem.[22][23]
José Valim aimed to create a programming language for large-scale sites and apps. Being a Ruby developer, he used the best features of Ruby, Erlang, and Clojure to develop a high-concurrency and low-latency language. Elixir was designed to handle large data volumes. Its speed and capabilities spread Elixir in telecommunication, eCommerce, and finance industries. [24]
On July 12, 2018, Honeypot released a mini-documentary on Elixir.[25]
Elixir mostly[26] follows Semantic Versioning and has only 1 major version with no plans for a second. Each of the minor versions supports a specific range of Erlang/OTP versions.[27]
with constructThe following examples can be run in an iex shell or saved in a file and run from the command line by typing elixir <filename>.
Classic Hello world example:
iex> IO.puts("Hello World!") Hello World!
Comprehensions
iex> for n <- [1,2,3,4,5], rem(n, 2) == 1, do: n*n [1, 9, 25]
Pattern Matching (destructuring)
iex> [1, a] = [1, 2] iex> a 2 iex> {:ok, [hello: a]} = {:ok, [hello: "world"]} iex> a "world"
Pattern Matching (multiple clauses)
iex> case File.read("path/to/file") do iex> {:ok, contents} -> IO.puts("found file: #{contents}") iex> {:error, reason} -> IO.puts("missing file: #{reason}") iex> end
Pipe Operator
iex> "1" |> String.to_integer() |> Kernel.*(2) 2
Modules
defmodule Fun do def fib(0), do: 0 def fib(1), do: 1 def fib(n), do: fib(n-2) + fib(n-1) end
Sequentially spawning a thousand processes
for num <- 1..1000, do: spawn fn -> IO.puts("#{num * 2}") end
Asynchronously performing a task
task = Task.async fn -> perform_complex_action() end other_time_consuming_action() Task.await task