Erlang (programming language): Difference between revisions

Content deleted Content added
Bot: Removing Commons:File:Mike williams.jpg (en). It was deleted on Commons by Túrelio (Copyright violation: No license information on source page).
BrainStack (talk | contribs)
Link suggestions feature: 3 links added.
 
(14 intermediate revisions by 11 users not shown)
Line 4:
| name = Erlang
| logo = Erlang logo.svg
| logo size = 120px140px
| paradigms = [[Multi-paradigm programming language|Multi-paradigm]]: [[Concurrent programming|concurrent]], [[Functional programming|functional]], [[Object oriented programming|object oriented]]
| family =
| designer = {{unbulleted list|[[Joe Armstrong (programmer)|Joe Armstrong]]|Robert Virding|Mike Williams}}
Line 20:
| file ext = .erl, .hrl
| license = [[Apache License 2.0]]
| website = {{URLurl|https://www.erlang.org}}
| 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 [[Immutable object|immutable]] data, [[pattern matching]], and [[functional programming]].<ref>Hitchhiker’s Tour of the BEAM – Robert Virding http://www.erlang-factory.com/upload/presentations/708/HitchhikersTouroftheBEAM.pdf</ref> The sequential subset of the Erlang language supports [[eager evaluation]], [[single assignment]], and [[dynamic typing]].
 
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 book |last=Armstrong |first=Joe |chapter=The development of Erlang |title=Proceedings of the second ACM SIGPLAN international conference on Functional programming |journal=ACM SIGPLAN Notices |date=August 1997 |volume=32 |issue=8 |pages=196–203 |doi=10.1145/258948.258967 |isbn=0897919181 |s2cid=6821037 }}</ref> According to co-inventor Joe Armstrong, the language went from lablaboratory product to real applications following the collapse of the next-generation [[AXE telephone exchange]] named [[:sv:AXE-N|''AXE-N'']] in 1995. As a result, Erlang was chosen for the next [[Asynchronous Transfer Mode]] (ATM) exchange ''AXD''.<ref name="hopl"/>
 
[[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. Erlang processes can be seen as "living" objects ([[object-oriented programming]]), with data encapsulation and [[message passing]], but capable of changing behavior during runtime. The Erlang runtime system provides strict [[process isolation]] between Erlang processes (this includes data and garbage collection, separated individually by each Erlang process) and transparent communication between processes (see [[Location transparency]]) on different Erlang nodes (on different hosts).
 
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 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 [[T-MobileDeutsche International AG|T-MobileTelekom]].<ref>{{cite web |url=http://www.ericsson.com/news/141204-inside-erlang-creator-joe-armstrong-tells-his-story_244099435_c |title=Ericsson |work=Ericsson.com |date=4 December 2014 |access-date=7 April 2018}}</ref>
 
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:
It is also the language of choice for [[Ejabberd]] – an [[XMPP]] messaging server.
 
[[Elixir_Elixir (programming_languageprogramming 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[[Internet of things|Internet of Things]] and blockchain. Apart from WhatsApp, there are other companies listed as Erlang's success stories:, including [[Vocalink]] (a MasterCard company), [[Goldman Sachs]], [[Nintendo]], AdRoll, [[Grindr]], [[BT Mobile]], [[Samsung]], [[OpenX (company)|OpenX]], and [[SITA (business services 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>
 
==Functional programming examples==
Line 138:
%% If fib_int/3 receives 0 as its first argument, then we're done, so
%% return the value in argument B. The second argument is denoted _ to
%% to disregard its value.
fib_int(0, _, B) -> B;
 
Line 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.
 
Erlang has no method to define classes, although there are external [[Library (computing)|libraries]] available.<ref>{{cite web |url=https://code.google.com/p/ect/ |title=ect – Erlang Class Transformation – add object-oriented programming to Erlang – Google Project Hosting |access-date=2 May 2015}}</ref>
 
=="Let it crash" coding style==
Line 251 ⟶ 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 secondly, for taking the appropriate action to correct the error condition.
 
==Concurrency and distribution orientation==
Line 299 ⟶ 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 361 ⟶ 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 [[T-MobileDeutsche International AG|T-MobileTelekom]].<ref>{{cite web |title=Who uses Erlang for product development? |work=Frequently asked questions about Erlang |url=http://erlang.org/faq/introduction.html#idp32141008 |access-date=16 July 2007 |quote=''The largest user of Erlang is (surprise!) Ericsson. Ericsson use it to write software used in telecommunications systems. Many dozens of projects have used it, a particularly large one is the extremely scalable AXD301 ATM switch.'' Other commercial users listed as part of the FAQ include: Nortel, Deutsche Flugsicherung (the German national [[air traffic control]] organisation), and T-Mobile.}}</ref> Although Erlang was designed to fill a niche and has remained an obscure language for most of its existence, its popularity is growing due to demand for concurrent services.<ref>{{cite web |title=Programming Erlang |url=http://www.ddj.com/linux-open-source/201001928?cid=RSSfeed_DDJ_OpenSource |access-date=13 December 2008 |quote=Virtually all language use shared state concurrency. This is very difficult and leads to terrible problems when you handle failure and scale up the system...Some pretty fast-moving startups in the financial world have latched onto Erlang; for example, the Swedish www.kreditor.se.}}</ref><ref>{{cite web |title=Erlang, the next Java |url=http://www.cincomsmalltalk.com/userblogs/ralph/blogView?showComments=true&entry=3364027251|archive-url=https://web.archive.org/web/20071011065959/http://cincomsmalltalk.com/userblogs/ralph/blogView?showComments=true&entry=3364027251|url-status=dead|archive-date=11 October 2007 |access-date=8 October 2008 |quote=I do not believe that other languages can catch up with Erlang anytime soon. It will be easy for them to add language features to be like Erlang. It will take a long time for them to build such a high-quality VM and the mature libraries for concurrency and reliability. So, Erlang is poised for success. If you want to build a multicore application in the next few years, you should look at Erlang.}}</ref>
Erlang has found some use in fielding [[massively multiplayer online role-playing game]] (MMORPG) servers.<ref>{{cite web
|last=Clarke
Line 379 ⟶ 377:
* [[Mix (build tool)]]
* [[Phoenix (web framework)]]
* [[Gleam (programming language)]] – a general-purpose, concurrent, functional high-level programming language that compiles to Erlang
 
==References==