Erlang (programming language)
Erlang | |
---|---|
Functional programming language |
|
Basic data | |
Paradigms : | functional , concurrent , predictive |
Publishing year: | 1987 |
Designer: | Joe Armstrong , Robert Virding, Mike Williams |
Developer: | Ericsson |
Current version | 23 (May 13, 2020) |
Typing : | dynamic , strong |
Important implementations : | Erlang |
Influenced by: | prolog |
Affected: | Clojure , Scala , Elixir |
Operating system : | Windows , Linux , macOS , Solaris |
License : | Apache Software License 2.0 |
www.erlang.org |

Erlang is a programming language developed at Ericsson by Joe Armstrong and others. It is named after the Danish mathematician Agner Krarup Erlang , but the name can also stand for Er icsson lang uage.
properties
When one speaks of Erlang, one usually means not only the relatively compact language, but also the runtime system and the extensive library . Together the system is called Erlang / OTP , where OTP is an abbreviation for The Open Telecom Platform . It is a middleware for the construction of distributed, high-availability systems. To be emphasized are z. B. the distributed databases Mnesia and CouchDB .
Erlang was originally created for the programming of applications in telecommunications , in particular for switching centers in telephone networks (switches) .
The special requirements there were directly incorporated into the design of the programming language and the runtime system:
- parallelism
- high availability
- Fault tolerance
- Exchange of modules during runtime etc.
Erlang satisfies the paradigms of functional , concurrent and distributed programming. Joe Armstrong , Erlang's spiritual father, preferred to refer to it as Concurrency Oriented Programming Language (COPL) , which can be roughly translated as a concurrently oriented programming language and suggests that processes are the most important objects in Erlang. He found the functional core less important, even if it is quite useful for concurrent programming because it avoids side effects.
Erlang is one of the few functional programming languages used in industry. Telephone and network equipment suppliers in particular use Erlang because of its good scalability and parallelism.
Processes are implemented in Erlang in a way that conserves resources. The Yaws web server written in Erlang with its high scalability is an example of this.
The syntax of Erlang is reminiscent of that of Prolog , which is not entirely surprising, since the system was initially available as an interpreter written in Prolog .
Based on the binary format used by Erlang , the general binary format BERT and a remote procedure call protocol based on it were developed.
Supplied software
The Erlang distribution comes with many useful additional tools that make programming applications much easier:
- OTP
- The O pen T elecom P latform facilitates the building of truly stable, parallel applications with additional features such as the dynamic exchange of code at runtime. OTP is a library that provides various behaviors that separate the functionality of an application from the model behind it (function call, client / server, etc.).
- ETS / DETS
- ETS and DETS (( D isk) E rlang T erm S torage) are two closely related storage systems for Erlang terms (tuples, lists, atoms, i.e. built-in data types) that offer great scalability and short access time. The basic operations are insert and lookup . A key-value structure (key-value storage) is used .
- Mnesia
- Mnesia is a full, built-in database system (DBMS) . Similar to ETS, Erlang terms are saved. Mnesia offers a distribution over several Erlang nodes (nodes) , storage in RAM or on the hard disk, several tables and atomic transactions.
The standard library also has powerful socket functions for TCP and UDP and many other small tool functions for lists, binary data, etc.
Examples
Calculation of the faculty
This code must be in the file test.erl
because the module (line 1) is also called test . The export directive makes the function fac () also callable from outside.
The two lines that begin with fac ( start are clauses called in. C ++ -Jargon could be the use of clauses with the overcharging compare. Each time you call a function of the number will be tried according to which clause the arguments given match ( match ) , where the first matching clause is used, the last clause ends with .
, all previous ones with ;
.
-module(test).
-export([fac/1,fac_tr/1]).
%%% nicht-endrekursive Version
fac(0) -> 1;
fac(N) -> N * fac(N-1).
%%% endrekursive Version (tail recursive)
fac_tr(0,Yet) -> Yet;
fac_tr(N,Yet) -> fac_tr(N-1,Yet*N).
%% Hilfsfunktion
fac_tr(N) -> fac_tr(N,1).
Quicksort
%% quicksort(List)
%% Sort a list of items
-module(quicksort).
-export([qsort/1]).
qsort([]) -> [];
qsort([Pivot|Rest]) ->
qsort([ X || X <- Rest, X < Pivot])
++ [Pivot] ++
qsort([ Y || Y <- Rest, Y >= Pivot]).
In the example above, the qsort function is called recursively until there is nothing left to sort .
The expression
[ X || X <- Rest, X < Pivot]
can be interpreted as “select all 'X', where 'X' is an element of 'rest' and 'X' is smaller than 'Pivot'”. This results in a very convenient way of handling lists (referred to in the literature as list comprehension ). In practical terms, it means returning a list that contains all of the remainder elements that are smaller than pivot (but not necessarily ordered by size).
A small distributed application that runs on two Erlang processes
-module(ping_pong).
-export([ping/0, pong/0]).
ping() ->
Receiver = spawn(ping_pong, pong, []),
Receiver ! {self(), ping},
receive
pong ->
pong
end.
pong() ->
receive
{Sender, ping} ->
Sender ! pong
end.
Message passing is used for communication . The operator! sends a message that is transmitted asynchronously, d. H. the process does not wait for the message to be received.
Mnesia
Entries in the Mnesia database (see above) are Erlang records ( records are syntactic sugar for easier handling of large tuples), i.e. tuples according to the pattern{recordname, key, field1, field2, field3}. The first field in the tuple must be the table name (in the case of records , the first field in the generated tuple is the name of the record ), the second field is the unique ID in the respective table that is typical for relational databases. Example:
%% Shell-Sitzung
% Record definieren
rd(table1,{field1,field2}).
% Mnesia-Instanz erzeugen (Struktur im aktuellen Verzeichnis)
mnesia:create_schema([node()]).
% Mnesia-Server starten
mnesia:start().
% Definiere Tabelle 'table1' mit den Feldern field1 und field2 (Wie der Record)
mnesia:create_table(table1,[{attributes,record_info(fields,table1)}]).
% Definiere Transaktion, die einen Datensatz einfügt.
F = fun() -> Record = #table1{ field1=helloWorld, field2=xyz }, mnesia:write(Record) end.
% Das gleiche wie
% F = fun() -> Record = {table1, helloWorld,xyz}, mnesia:write(Record) end.
% Führe atomare Transaktion aus.
mnesia:transaction(F).
% Query-Transaktion. qlc:q() kompiliert eine Listenkomprehension, qlc:e() führt sie aus.
G = fun() -> Query = qlc:q([X || X <- mnesia:table(table1)]), qlc:e(Query) end.
% Führe Transaktion aus. ListOfTuples ist eine Liste der Tupel, die die Anfrage erfüllen
{atomic, ListOfTuples} = mnesia:transaction(G).
mnesia:stop().
Prominent uses
- AnyDesk - remote maintenance software
- CouchDB - Document-oriented database
- ejabberd - XMPP - Server
- RabbitMQ - AMQP Messaging Server
- Riak - database
- SimpleDB - Amazon Web Services database
- WhatsApp backend - cellular messenger
- Wings 3D modeler
- YXA - SIP server
- Zotonic - CMS / Framework
Commercial use by Erlang
Erlang is one of the few functional programming languages that is also used in industry. Well-known users include:
- Alteon / Bluetail / Nortel (distributed, fault-tolerant email system, SSL accelerator)
- AnyDesk - remote maintenance software
- Cellpoint (location-based mobile services)
- Corelatus ( SS7 signaling black box).
- Ericsson (AXD301 switch )
- Facebook ( ejabberd -based chat engine)
- Finnish Meteorological Institute (data acquisition and real-time monitoring)
- GitHub (for RPC)
- IN Switch Solutions (ePIN electronic payment system)
- Mobilearts ( GSM and UMTS services)
- Motivity Telecom (SS7 / ISDN Gateways )
- Netkit Solutions (network technology monitoring & operations support systems)
- Process-one (commercializes the ejabberd XMPP server)
- Telekom Germany (mobile operator)
- Telia (telecom service provider)
- Tenerife Skunkworks (online poker server)
- Clustrx (HPC-OS)
- WhatsApp (mobile messenger via XMPP )
- Tambur.io ( WebSocket Messaging Gateway as Software as a Service )
literature
- Pavlo Baron: Erlang / OTP - platform for massively parallel and fault-tolerant systems . Open Source Press, Munich 2012, ISBN 978-3-941841-45-1
Web links
- www.erlang.org - Homepage of Open Source Erlang
- erlangcentral.org - Erlang community site
- Tim Pritlove : Erlang Podcast on CRE (March 2008)
- 24c3 - Conceptual Introduction to Erlang ( Video )
- Programming Rules and Conventions
- yaws.hyber.org - Homepage of the "Yaws" web server
Individual evidence
- ↑ www.erlang.org . May 13, 2020.
- ↑ github.com . May 13, 2020.
- ↑ Interview with Joe Armstrong on CIO.com.au (English)
- ↑ erlang.org
- ↑ bert-rpc.org
- ↑ github.com
- ↑ erlang-solutions.com ( Memento from December 30, 2011 in the Internet Archive )
- ↑ blog.whatsapp.com
- ↑ tambur.io