Content deleted Content added
RaincIouds (talk | contribs) →Processes: bare link |
BrainStack (talk | contribs) Link suggestions feature: 3 links added. |
||
(30 intermediate revisions by 24 users not shown) | |||
Line 4:
| name = Erlang
| logo = Erlang logo.svg
| logo size =
| paradigms = [[Multi-paradigm programming language|Multi-paradigm]]: [[Concurrent programming|concurrent]], [[Functional programming|functional]]
| family =
Line 20:
| file ext = .erl, .hrl
| license = [[Apache License 2.0]]
| website = {{
| wikibooks = Erlang Programming
}}
'''Erlang''' ({{IPAc-en|ˈ|ɜr|l|æ|ŋ}} {{respell|UR|lang}}) is a [[General-purpose programming language|general-purpose]], [[concurrent computing|concurrent]], [[Functional programming|functional]] [[High-level programming language|high-level]] [[programming language]], and a [[Garbage collection (computer science)|garbage-collected]] [[runtime system]]. The term Erlang is used interchangeably with Erlang/OTP, or [[Open Telecom Platform]] (OTP), which consists of the Erlang [[runtime system]], several ready-to-use components (OTP) mainly written in Erlang, and a set of [[Systems architecture|design principles]] for Erlang programs.<ref>{{cite web |url=http://erlang.org/doc/system_architecture_intro/sys_arch_intro.html#id58791 |title=Erlang – Introduction |website=erlang.org |access-date=6 February 2017 |archive-date=8 September 2019 |archive-url=https://web.archive.org/web/20190908105859/http://erlang.org/doc/system_architecture_intro/sys_arch_intro.html#id58791 |url-status=dead }}</ref>
The Erlang [[runtime system]] is designed for systems with these traits:
Line 34:
*[[Hot swapping#Software|Hot swapping]], where code can be changed without stopping a system.<ref>{{cite web |last1=Armstrong |first1=Joe |last2=Däcker |first2=Bjarne |last3=Lindgren |first3=Thomas |last4=Millroth |first4=Håkan |title=Open-source Erlang – White Paper |url=http://ftp.sunet.se/pub/lang/erlang/white_paper.html|archive-url=https://web.archive.org/web/20111025022940/http://ftp.sunet.se/pub/lang/erlang/white_paper.html |archive-date=25 October 2011 |access-date=31 July 2011}}</ref>
The Erlang [[programming language]] has
A normal Erlang application is built out of hundreds of small Erlang processes.
Line 41:
==History==
The name ''Erlang'', attributed to Bjarne Däcker, has been presumed by those working on the telephony switches (for whom the language was designed) to be a reference to Danish mathematician and engineer [[Agner Krarup Erlang]] and a [[Abbreviation#Syllabic abbreviation|syllabic abbreviation]] of "Ericsson Language".<ref name="hopl"/><ref>{{cite web |url=http://www.erlang.org/pipermail/erlang-questions/1999-February/000098.html |title=Erlang, the mathematician? |date=February 1999 }}</ref><ref>{{cite web |url=https://foldoc.org/Erlang |title=Free Online Dictionary of Computing: Erlang }}</ref> Erlang was designed with the aim of improving the development of telephony applications.<ref>{{cite web|url=http://erlang.org/course/history.html|title=History of Erlang|website=Erlang.org}}</ref> The initial version of Erlang was implemented in [[Prolog]] and was influenced by the programming language [[PLEX (programming language)|PLEX]] used in earlier Ericsson exchanges. By 1988 Erlang had proven that it was suitable for prototyping telephone exchanges, but the Prolog interpreter was far too slow. One group within Ericsson estimated that it would need to be 40 times faster to be suitable for production use. In 1992, work began on the [[BEAM (Erlang virtual machine)|BEAM]] [[virtual machine]] (VM), which compiles Erlang to C using a mix of natively compiled code and [[threaded code]] to strike a balance between performance and disk space.<ref>{{cite
[[File:Robert Virding and Joe Armstrong, 2013.jpg|thumb|Robert Virding and Joe Armstrong, 2013]]
In February 1998, Ericsson Radio Systems banned the in-house use of Erlang for new products, citing a preference for non-proprietary languages.<ref>{{cite thesis|url=https://cogsys.uni-bamberg.de/team/schmid/uoshp/lehreuos/fp01-www/fp-referate/erlang/bjarnelic.pdf#page=45|title=Concurrent Functional Programming for Telecommunications: A Case Study of Technology Introduction|first=Bjarne|last=Däcker|date=October 2000|publisher=Royal Institute of Technology|page=37}}</ref> The ban caused Armstrong and others to make plans to leave Ericsson.<ref name="questions"/> In March 1998 Ericsson announced the AXD301 switch,<ref name="hopl"/> containing over a million lines of Erlang and reported to achieve a [[high availability]] of [[nines (engineering)|nine "9"s]].<ref>
{{cite web |url=http://www.rabbitmq.com/resources/armstrong.pdf |title=Concurrency Oriented Programming in Erlang |date=9 November 2002}}
</ref> In December 1998, the implementation of Erlang was open-sourced and most of the Erlang team resigned to form a new company, Bluetail AB.<ref name="hopl"/> Ericsson eventually relaxed the ban and re-hired Armstrong in 2004.<ref name="questions">{{cite web |url=http://erlang.org/pipermail/erlang-questions/2006-July/021368.html |title=question about Erlang's future |date=6 July 2010}}</ref>
In 2006, native [[symmetric multiprocessing]] support was added to the runtime system and VM.<ref name="hopl"/>
===Processes===
Erlang applications are built of very lightweight Erlang processes in the Erlang runtime system
Joe Armstrong, co-inventor of Erlang, summarized the principles of processes in his [[Doctor of Philosophy|PhD]] [[thesis]]:<ref>{{Cite thesis |last=Armstrong |first=Joe |title=Making reliable distributed systems in the presence of software errors |date=20 November 2003 |degree=DTech |publisher=The Royal Institute of Technology |place=Stockholm, Sweden}}</ref>
Line 70 ⟶ 68:
===Usage===
In 2014, [[Ericsson]] reported Erlang was being used in its support nodes, and in [[GPRS]], [[3G]] and [[LTE (telecommunication)|LTE]] mobile networks worldwide and also by [[Nortel]] and [[
Erlang is used in [[RabbitMQ]]. As [[Tim Bray]], director of Web Technologies at [[Sun Microsystems]], expressed in his keynote at [[O'Reilly Open Source Convention]] (OSCON) in July 2008:
Line 77 ⟶ 75:
Erlang is the programming language used to code [[WhatsApp]].<ref>{{cite web |url=https://www.fastcompany.com/3026758/inside-erlang-the-rare-programming-language-behind-whatsapps-success |title=Inside Erlang, The Rare Programming Language Behind WhatsApp's Success |work=fastcompany.com |date=21 February 2014 |access-date=12 November 2019}}</ref>
It is also the language of choice for [[Ejabberd]] – an [[XMPP]] messaging server.
[[Elixir_(programming_language)|Elixir]] is a programming language that compiles into BEAM byte code (via Erlang Abstract Format).<ref>{{Cite web |title=Erlang/Elixir Syntax: A Crash Course |url=https://elixir-lang.org/crash-course.html |access-date=2022-10-10 |website=elixir-lang.github.com |language=en}}</ref>▼
▲[[
Since being released as open source, Erlang has been spreading beyond telecoms, establishing itself in other vertical markets such as FinTech, gaming, healthcare, automotive, internet of things and blockchain. Apart from WhatsApp, there are other companies listed as Erlang's success stories: [[Vocalink]] (a MasterCard company), [[Goldman Sachs]], [[Nintendo]], AdRoll, [[Grindr]], [[BT Mobile]], [[Samsung]], [[OpenX (company)|OpenX]], and [[SITA (company)|SITA]].<ref>{{cite web |url=https://www.erlang-solutions.com/blog/which-companies-are-using-erlang-and-why-mytopdogstatus.html |title=Which companies are using Erlang, and why? #MyTopdogStatus |work=erlang-solutions.com |date=11 September 2019 |access-date=15 March 2020}}</ref><ref>{{Cite web |url=https://www.erlang-solutions.com/blog/which-new-companies-are-using-erlang-and-elixir-mytopdogstatus.html |title=Which new companies are using Erlang and Elixir? #MyTopdogStatus |website=erlang-solutions.com |date=2 March 2020 | access-date=2020-06-24}}</ref>▼
▲Since being released as open source, Erlang has been spreading beyond telecoms, establishing itself in other vertical markets such as FinTech, gaming, healthcare, automotive,
==Functional programming examples==
Line 119:
%% The order in which these function signatures are declared is a vital
%% part of this module's functionality
fib(0) -> 0;▼
%% If fib/1 receives a negative number, then return the atom err_neg_val
%% Normally, such defensive coding is discouraged due to Erlang's 'Let
%% it Crash' philosophy
fib(N) when N < 0 -> err_neg_val;
%% If fib/1 is passed
▲fib(0) -> 0;
%% For all other values, call the private function fib_int/3 to perform
%% the calculation
fib(N) -> fib_int(N-1, 0, 1).
%% ---------------------------------------------------------------------
Line 142 ⟶ 136:
%% ---------------------------------------------------------------------
%% If fib_int/3 receives
%% return the value in argument B. The
%% disregard its value.
▲fib_int(1, _, B) -> B;
%% For all other argument combinations, recursively call fib_int/3
%% where each call does the following:
%% - decrement counter N
%% -
%% - pass the sum of the second and third arguments as the new
%%
fib_int(N, A, B) -> fib_int(N-1, B, A+B).
</syntaxhighlight>
Omitting the comments gives a much shorter program.
<syntaxhighlight lang="erlang">
Line 164 ⟶ 156:
-export([fib/1]).
fib(N) when N < 0 -> err_neg_val;
fib(
fib(N) -> fib_int(N-1, 0, 1).
fib_int(
fib_int(N, A, B) -> fib_int(N-1, B, A+B).
</syntaxhighlight>
Line 250 ⟶ 241:
;Strings: Strings are written as doubly quoted lists of characters. This is syntactic sugar for a list of the integer [[Unicode]] code points for the characters in the string. Thus, for example, the string "cat" is shorthand for <code>[99,97,116]</code>.<ref>{{cite web |url=http://erlang.org/doc/apps/stdlib/unicode_usage.html#string-and-character-literals |title=String and Character Literals |access-date=2 May 2015}}</ref>
;Records: Records provide a convenient way for associating a tag with each of the elements in a tuple. This allows one to refer to an element of a tuple by name and not by position. A pre-compiler takes the record definition and replaces it with the appropriate tuple reference.
=="Let it crash" coding style==
Line 260 ⟶ 249:
A typical Erlang application is written in the form of a supervisor tree. This architecture is based on a hierarchy of processes in which the top level process is known as a "supervisor". The supervisor then spawns multiple child processes that act either as workers or more, lower level supervisors. Such hierarchies can exist to arbitrary depths and have proven to provide a highly scalable and fault-tolerant environment within which application functionality can be implemented.
Within a supervisor tree, all supervisor processes are responsible for managing the lifecycle of their child processes, and this includes handling situations in which those child processes crash. Any process can become a supervisor by first spawning a child process, then calling <code>erlang:monitor/2</code> on that process. If the monitored process then crashes, the supervisor will receive a message containing a tuple whose first member is the atom <code>'DOWN'</code>. The supervisor is responsible firstly for listening for such messages and
==Concurrency and distribution orientation==
Line 308 ⟶ 297:
==Implementation==
The official [[reference implementation]] of Erlang uses [[BEAM (Erlang virtual machine)|BEAM]].<ref>{{cite web |url=http://erlang.org/doc/reference_manual/code_loading.html#id90080 |title=Erlang – Compilation and Code Loading |website=erlang.org |access-date=2017-12-21}}</ref> BEAM is included in the official distribution of Erlang, called Erlang/OTP. BEAM executes [[bytecode]] which is converted to [[threaded code]] at load time. It also includes a native code compiler on most platforms, developed by the High Performance Erlang Project (HiPE) at [[Uppsala University]]. Since October 2001 the HiPE system is fully integrated in Ericsson's Open Source Erlang/OTP system.<ref>{{cite web |title=High Performance Erlang |url=http://www.it.uu.se/research/group/hipe/ |access-date=26 March 2011}}</ref> It also supports interpreting, directly from source code via [[abstract syntax tree]], via script as of R11B-5 release of Erlang.
==Hot code loading and modules==
Line 370 ⟶ 359:
In 1998, Ericsson released Erlang as [[free and open-source software]] to ensure its independence from a single vendor and to increase awareness of the language. Erlang, together with libraries and the real-time distributed database [[Mnesia]], forms the OTP collection of libraries. Ericsson and a few other companies support Erlang commercially.
Since the open source release, Erlang has been used by several firms worldwide, including [[Nortel Networks|Nortel]] and [[
Erlang has found some use in fielding [[massively multiplayer online role-playing game]] (MMORPG) servers.<ref>{{cite web
|last=Clarke
Line 388 ⟶ 377:
* [[Mix (build tool)]]
* [[Phoenix (web framework)]]
* [[Gleam (programming language)]] – a general-purpose, concurrent, functional high-level programming language that compiles to Erlang
==References==
Line 496 ⟶ 486:
{{Commons category}}
{{Wikibooks|Erlang Programming}}
* [[iarchive:ErlangTheMovie|"Erlang: The Movie"]]
* {{Official website}}
|