Content deleted Content added
No edit summary |
|||
(44 intermediate revisions by 28 users not shown) | |||
Line 1:
{{Short description|Programming language running on the Erlang virtual machine}}
{{
{{Infobox programming language
| name = Elixir
| title =
| logo = [[File:
| logo caption = Elixir
| paradigms = [[multi-paradigm programming language|multi-paradigm]]: [[functional programming|functional]], [[concurrent programming|concurrent]], [[distributed programming|distributed]], [[process-oriented programming|process-oriented]]
| typing = [[type system|dynamic]], [[strong typing|strong
| influenced = [[Gleam (programming language)|Gleam]], [[LFE (programming language)|LFE]]
| platform = [[Erlang (programming language)|Erlang]]
| license = [[Apache License 2.0]]<ref>{{cite web|url=https://github.com/elixir-lang/elixir/blob/master/LICENSE|title=elixir/LICENSE at master · elixir-lang/elixir · GitHub|work=GitHub}}</ref>
Line 14:
| year = {{start date and age|2012}}
| influenced_by = [[Clojure]], [[Erlang (programming language)|Erlang]], [[Ruby (programming language)|Ruby]]
| designer =
| origin = Brazil
| latest release version = {{wikidata|property|edit|reference|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|single|P348|P577}}}}
Line 22 ⟶ 23:
}}
'''Elixir''' is a [[functional programming|functional]], [[concurrent computing|concurrent]], [[High-level programming language|high-level]] [[General-purpose programming language|general-purpose]] [[programming language]] that runs on the [[BEAM (Erlang virtual machine)|BEAM]] [[virtual machine]], which is also used to implement the [[Erlang (programming language)|Erlang]] programming language.<ref name=":0">{{Cite news|url=https://www.eliteinfoworld.com/blog/popular-programming-languages-2018/|title=Most Popular Programming Languages of 2018 - Elite Infoworld Blog|date=2018-03-30|access-date=2018-05-08|archive-date=2018-05-09|archive-url=https://web.archive.org/web/20180509080342/https://www.eliteinfoworld.com/blog/popular-programming-languages-2018/|url-status=dead}}</ref> Elixir builds on top of Erlang and shares the same abstractions for building [[Distributed computing|distributed]], [[fault-tolerant]] applications. Elixir also provides
The community organizes yearly events in the United States,<ref>{{Cite web|title = ElixirConf|url = http://elixirconf.com/|access-date = 2018-07-11}}</ref> Europe,<ref>{{Cite web|title = ElixirConf|url = http://elixirconf.eu/|access-date = 2018-07-11}}</ref> and Japan,<ref>{{Cite web|title = Erlang & Elixir Fest|url = https://elixir-fest.jp/|access-date = 2019-02-18}}</ref> as well as minor local events and conferences.<ref>{{Cite web|title = Elixir LDN|url = http://www.elixir.london/|access-date = 2018-07-12}}</ref><ref>{{Cite web|title = EMPEX - Empire State Elixir Conference|url = http://empex.co/|access-date = 2018-07-12}}</ref>
== History ==
José Valim
Elixir
== Versioning ==
== Features ==
* [[Compiler|Compiles]] to [[bytecode]] for the [[BEAM (Erlang virtual machine)|BEAM virtual machine]] of [[Erlang (programming language)|Erlang]].<ref name="elixirhome">{{ cite web |url=https://elixir-lang.org/|title=Elixir | access-date=2014-09-07}}</ref>
* Scalability and fault-tolerance, thanks to Erlang's lightweight concurrency mechanisms<ref name="elixirhome" />
* [[Mix (build tool)|Built-in tooling]] for managing dependencies, code compilation, running tests, formatting code, remote debugging and more.
* An interactive [[Read–eval–print loop|REPL]] inside running programs, including [[Phoenix (web framework)|Phoenix]] web servers
* Everything is an [[Expression (computer science)|expression]]<ref name="elixirhome" />
* [[Pattern matching]]<ref name="elixirhome" /> to promote assertive code<ref>{{Cite web |date=24 September 2014 |title=Writing assertive code with Elixir |url=http://blog.plataformatec.com.br/2014/09/writing-assertive-code-with-elixir/ |access-date=2018-07-05}}</ref>
Line 47 ⟶ 48:
* [[Shared nothing architecture|Shared nothing concurrent programming]] via message passing ([[actor model]])<ref>{{cite book |last1=Loder |first1=Wolfgang |url=https://leanpub.com/erlangandelixirforimperativeprogrammers |title=Erlang and Elixir for Imperative Programmers |date=12 May 2015 |publisher=Leanpub |___location="Chapter 16: Code Structuring Concepts", section title "Actor Model" |access-date=7 July 2015}}</ref>
* [[Lazy evaluation|Lazy]] and [[Futures and promises|async collections]] with streams
*
* Hygienic [[metaprogramming]] by direct access to the [[abstract syntax tree]] (AST).<ref name="elixirhome" />
* Code execution at compile time. The Elixir compiler also runs on the
* [[Polymorphism (computer science)|Polymorphism]] via a mechanism called protocols. [[Dynamic dispatch]], as in [[Clojure]], however, without [[multiple dispatch]] because Elixir protocols dispatch on a single type.
* Support for documentation via Python-like docstrings in the [[Markdown]] formatting language<ref name="elixirhome" />
Line 57 ⟶ 58:
The following examples can be run in an <code>iex</code> [[Shell (computing)|shell]] or saved in a file and run from the [[command line]] by typing <code>elixir ''<filename>''</code>.
Classic [["Hello, World!" program|Hello world]] example:
<syntaxhighlight lang="iex">
Line 72 ⟶ 73:
[2, 4, 6, 8, 10]
iex> %{values: 1..5} |> Map.get(:values) |> Enum.map(& &1 * 2) |> Enum.sum()
30
</syntaxhighlight>
Line 98 ⟶ 99:
iex> for n <- 1..5, rem(n, 2) == 1, do: n*n
[1, 9, 25]
</syntaxhighlight>
Asynchronously reading files with streams:
<syntaxhighlight lang="elixir">
1..5
|> Task.async_stream(&File.read!("#{&1}.txt"))
|> Stream.filter(fn {:ok, contents} -> String.trim(contents) != "" end)
|> Enum.join("\n")
</syntaxhighlight>
Line 128 ⟶ 137:
other_time_consuming_action()
Task.await task
</syntaxhighlight>{{cn|date=June 2023}}
== See also ==
Line 138 ⟶ 143:
* [[Concurrent computing]]
* [[Distributed computing]]
* [[Parallel computing]]
== References ==
{{Reflist|30em}}
==
* {{Cite book |author1=Simon St. Laurent |author2=J. Eisenberg |date=December 22, 2016 |title=Introducing Elixir: Getting Started in Functional Programming 2nd Edition|publisher=[[O'Reilly Media]] |isbn=978-1491956779 |language=en}}
* {{Cite book |author=Sasa Juric |date=January 12, 2019 |title=Elixir in Action 2nd Edition |publisher=[[Manning Publications]] |isbn=978-1617295027 |language=en}}
{{Programming languages}}
|