HOME

TheInfoList



OR:

Elixir is a functional, concurrent, high-level general-purpose
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
that runs on the BEAM
virtual machine In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
, which is also used to implement the Erlang programming language. Elixir builds on top of Erlang and shares the same abstractions for building distributed, fault-tolerant applications. Elixir also provides tooling and an extensible design. The latter is supported by compile-time
metaprogramming Metaprogramming is a computer programming technique in which computer programs have the ability to treat other programs as their data. It means that a program can be designed to read, generate, analyse, or transform other programs, and even modi ...
with macros and polymorphism via protocols. The community organizes yearly events in the United States, Europe, and Japan, as well as minor local events and conferences.


History

José Valim created the Elixir programming language as a
research and development Research and development (R&D or R+D), known in some countries as OKB, experiment and design, is the set of innovative activities undertaken by corporations or governments in developing new services or products. R&D constitutes the first stage ...
project at Plataformatec. His goals were to enable higher extensibility and productivity in the Erlang VM while maintaining compatibility with Erlang's ecosystem. Elixir is aimed at large-scale sites and apps. It uses features of
Ruby Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
, Erlang, and
Clojure Clojure (, like ''closure'') is a dynamic programming language, dynamic and functional programming, functional dialect (computing), dialect of the programming language Lisp (programming language), Lisp on the Java (software platform), Java platfo ...
to develop a high-concurrency and low-latency language. It was designed to handle large data volumes. Elixir is also used in telecommunications, e-commerce, and finance. In 2021, the Numerical Elixir effort was announced with the goal of bringing machine learning, neural networks, GPU compilation, data processing, and computational notebooks to the Elixir ecosystem.


Versioning

Each of the minor versions supports a specific range of Erlang/ OTP versions. The current stable release version is .


Features

* Compiles to
bytecode Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (normal ...
for the BEAM virtual machine of Erlang. Full interoperability with Erlang code, without runtime impact. * Scalability and fault-tolerance, thanks to Erlang's lightweight concurrency mechanisms * Built-in tooling for managing dependencies, code compilation, running tests, formatting code, remote debugging and more. * An interactive REPL inside running programs, including Phoenix web servers, with code reloading and access to internal state * Everything is an expression *
Pattern matching In computer science, pattern matching is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually must be exact: "either it will or will not be a ...
to promote assertive code * Type hints for static analysis tools * Immutable data, with an emphasis, like other functional languages, on
recursion Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in m ...
and
higher-order function In mathematics and computer science, a higher-order function (HOF) is a function that does at least one of the following: * takes one or more functions as arguments (i.e. a procedural parameter, which is a parameter of a procedure that is itself ...
s instead of side-effect-based looping * Shared nothing concurrent programming via message passing (
actor model The actor model in computer science is a mathematical model of concurrent computation that treats an ''actor'' as the basic building block of concurrent computation. In response to a message it receives, an actor can: make local decisions, create ...
) * Lazy and async collections with streams * Railway oriented programming via the with construct * Hygienic
metaprogramming Metaprogramming is a computer programming technique in which computer programs have the ability to treat other programs as their data. It means that a program can be designed to read, generate, analyse, or transform other programs, and even modi ...
by direct access to the abstract syntax tree (AST). Libraries often implement small domain-specific languages, such as for databases or testing. * Code execution at compile time. The Elixir compiler also runs on the BEAM, so modules that are being compiled can immediately run code which has already been compiled. * Polymorphism via a mechanism called protocols. Dynamic dispatch, as in
Clojure Clojure (, like ''closure'') is a dynamic programming language, dynamic and functional programming, functional dialect (computing), dialect of the programming language Lisp (programming language), Lisp on the Java (software platform), Java platfo ...
, however, without
multiple dispatch Multiple dispatch or multimethods is a feature of some programming languages in which a Subroutine, function or Method (computer programming), method can be dynamic dispatch, dynamically dispatched based on the run time (program lifecycle phase), ...
because Elixir protocols dispatch on a single type. * Support for documentation via Python-like docstrings in the Markdown formatting language *
Unicode Unicode or ''The Unicode Standard'' or TUS is a character encoding standard maintained by the Unicode Consortium designed to support the use of text in all of the world's writing systems that can be digitized. Version 16.0 defines 154,998 Char ...
support and
UTF-8 UTF-8 is a character encoding standard used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode Transformation Format 8-bit''. Almost every webpage is transmitted as UTF-8. UTF-8 supports all 1,112,0 ...
strings


Examples

The following examples can be run in an iex
shell Shell may refer to: Architecture and design * Shell (structure), a thin structure ** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses Science Biology * Seashell, a hard outer layer of a marine ani ...
or saved in a file and run from the command line by typing elixir ''''. Classic Hello world example: iex> IO.puts("Hello World!") Hello World! Pipe operator: iex> "Elixir" , > String.graphemes() , > Enum.frequencies() % iex> % , > Map.get(:values) , > Enum.map(& &1 * 2) , 4, 6, 8, 10 iex> % , > Map.get(:values) , > Enum.map(& &1 * 2) , > Enum.sum() 30
Pattern matching In computer science, pattern matching is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually must be exact: "either it will or will not be a ...
(a.k.a. destructuring): iex> % = % iex> x 5 iex> = iex> rest , 3 Pattern matching with multiple clauses: iex> case File.read("path/to/file") do iex> -> IO.puts("found file: #") iex> -> IO.puts("missing file: #") iex> end List comprehension: iex> for n <- 1..5, rem(n, 2)

1, do: n*n , 9, 25
Asynchronously reading files with streams: 1..5 , > Task.async_stream(&File.read!("#.txt")) , > Stream.filter(fn -> String.trim(contents) != "" end) , > Enum.join("\n") Multiple function bodies with guards: def fib(n) when n in
, 1 The comma is a punctuation mark that appears in several variants in different languages. Some typefaces render it as a small line, slightly curved or straight, but inclined from the vertical; others give it the appearance of a miniature fille ...
do: n def fib(n), do: fib(n-2) + fib(n-1)
Relational databases with the Ecto library: schema "weather" do field :city # Defaults to type :string field :temp_lo, :integer field :temp_hi, :integer field :prcp, :float, default: 0.0 end Weather , > where(city: "Kraków") , > order_by(:temp_lo) , > limit(10) , > Repo.all Sequentially spawning a thousand processes: for num <- 1..1000, do: spawn fn -> IO.puts("#") end Asynchronously performing a task: task = Task.async fn -> perform_complex_action() end other_time_consuming_action() Task.await task


See also

*
Concurrent computing Concurrent computing is a form of computing in which several computations are executed '' concurrently''—during overlapping time periods—instead of ''sequentially—''with one completing before the next starts. This is a property of a syst ...
*
Distributed computing Distributed computing is a field of computer science that studies distributed systems, defined as computer systems whose inter-communicating components are located on different networked computers. The components of a distributed system commu ...
*
Parallel computing Parallel computing is a type of computing, computation in which many calculations or Process (computing), processes are carried out simultaneously. Large problems can often be divided into smaller ones, which can then be solved at the same time. ...


References


Further reading

* * {{Authority control Concurrent programming languages Functional languages Pattern matching programming languages Programming languages Programming languages created in 2012 Software using the Apache license