Elixir (programming language)

From Infogalactic: the planetary knowledge core
Jump to: navigation, search
Elixir (programming language)
elixir programming language
Paradigm multi-paradigm: functional, concurrent, distributed, process-oriented
First appeared 2011; 13 years ago (2011)
Stable release 1.9.2 / 11 October 2019; 4 years ago (2019-10-11)[1]
Typing discipline dynamic, strong, duck
Platform Erlang
License Apache License 2.0[2]
Filename extensions .ex, .exs
Website elixir-lang.org
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] and Divvy[13], and for building embedded systems.[14][15] The community organizes yearly events in the United States,[16] Europe[17] and Japan[18] as well as minor local events and conferences.[19][20]

History

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.[21][22]

On July 12, 2018, Honeypot released a mini-documentary on Elixir.[23]

Versioning

Elixir 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.[24]

Features

Examples

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

Noteworthy Elixir projects

  • Mix is a build automation tool that provides tasks for creating, compiling, and testing Elixir projects, managing its dependencies, and more.[28]
  • Phoenix is a web development framework written in Elixir which implements the server-side Model View Controller (MVC) pattern.[29]
  • Nerves is a platform, framework, and tooling environment for building embedded systems and devices.[15][30]
  • Ecto is the database wrapper and query generator for Elixir.[31]

See also

References

  1. Lua error in package.lua at line 80: module 'strict' not found.
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. Lua error in package.lua at line 80: module 'strict' not found.
  4. Lua error in package.lua at line 80: module 'strict' not found.
  5. Lua error in package.lua at line 80: module 'strict' not found.
  6. Lua error in package.lua at line 80: module 'strict' not found.
  7. Lua error in package.lua at line 80: module 'strict' not found.
  8. Lua error in package.lua at line 80: module 'strict' not found.
  9. Lua error in package.lua at line 80: module 'strict' not found.
  10. Lua error in package.lua at line 80: module 'strict' not found.
  11. Lua error in package.lua at line 80: module 'strict' not found.
  12. Lua error in package.lua at line 80: module 'strict' not found.
  13. Lua error in package.lua at line 80: module 'strict' not found.
  14. Lua error in package.lua at line 80: module 'strict' not found.
  15. 15.0 15.1 Lua error in package.lua at line 80: module 'strict' not found.
  16. Lua error in package.lua at line 80: module 'strict' not found.
  17. Lua error in package.lua at line 80: module 'strict' not found.
  18. Lua error in package.lua at line 80: module 'strict' not found.
  19. Lua error in package.lua at line 80: module 'strict' not found.
  20. Lua error in package.lua at line 80: module 'strict' not found.
  21. Lua error in package.lua at line 80: module 'strict' not found.
  22. Lua error in package.lua at line 80: module 'strict' not found.
  23. Lua error in package.lua at line 80: module 'strict' not found.
  24. Lua error in package.lua at line 80: module 'strict' not found.
  25. 25.0 25.1 25.2 25.3 25.4 25.5 Lua error in package.lua at line 80: module 'strict' not found.
  26. Lua error in package.lua at line 80: module 'strict' not found.
  27. Lua error in package.lua at line 80: module 'strict' not found.
  28. Lua error in package.lua at line 80: module 'strict' not found.
  29. Lua error in package.lua at line 80: module 'strict' not found.
  30. Lua error in package.lua at line 80: module 'strict' not found.
  31. Lua error in package.lua at line 80: module 'strict' not found.

External links