![]() | This article contains content that is written like an advertisement. (June 2020) |
![]() | |
Paradigm | multi-paradigm: functional, concurrent, distributed, process-oriented |
---|---|
First appeared | 2011 |
Stable release | 1.12[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 BEAM virtual machine used to implement the Erlang programming language.[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]Brex,[7] E-MetroTel,[8]Pinterest,[9] Moz,[10]Bleacher Report,[11]The Outline,[12]Inverse,[13] Divvy,[14]FarmBot[15] and for building embedded systems.[16][17] The community organizes yearly events in the United States,[18] Europe[19] and Japan[20] as well as minor local events and conferences.[21][22]
José Valim is the 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.[23][24]
José Valim aimed to create a programming language for large-scale sites and apps. Being a Ruby developer, he used 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.[25]
On July 12, 2018, Honeypot released a mini-documentary on Elixir.[26]
Elixir mostly[27] 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.[28]
with
construct[31]The 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
By: Wikipedia.org
Edited: 2021-06-18 18:12:51
Source: Wikipedia.org