Erlang programming language
|
Erlang is a general-purpose concurrent programming language and runtime system. The sequential sub-set of Erlang is a functional language, with strict evaluation, single assignment and dynamic typing. It was designed at Ericsson to support distributed, fault-tolerant, soft-real-time, non-stop applications.
It is named after A. K. Erlang. It is sometimes mistakenly thought that its name is as abbreviation of ERicsson LANGuage, owing to its heavy use inside Ericsson.
Contents |
Functional language
Code looks like this:
-module(fact). -export([fac/1]). fac(0) -> 1; fac(N) where N > 0 -> N * fac(N-1).
Below is an implementation of a Quicksort algorithm.
%% 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]).
The above example recursively calls the function qsort
until there is no more to be sorted. The expression [ X || X <- Rest, X < Pivot]
can be read as "Chose all X
where X
is a member of Rest
and X
is less than Pivot
", resulting in a very easy way of handling Lists. Since you can evaluate any boolean expression between two different datatypes, the evaluation is straight forward - for example, 1 < a
will return true
.
However, a compare function can be used if the order on which Erlang bases its return value (true
or false
) needs to be changed. For example, if we would want an ordered list where a > 1
evaluates true
.
Concurrency oriented language
Main strength of Erlang is support for concurrency. It has small but powerful set of primitives to create threads and communicate between them. Location of thread is transparent (it can be within the same operating system process or on different computer).
Code examples:
Pid = spawn(Mod, Func, Args) % execute function Func as new thread
Pid ! a_message % send message to the thread (asynchronously)
receive % receive message sent to this thread a_message -> do_something end.
Erlang contains mechanisms to deal with errors and to ensure high availability of the whole system. Dynamical replacement of code (hot swapping) is supported.
Distribution
Erlang was released as open source to ensure its dependence on single source and to increase awareness of the language. Distribution of the language together with libraries and real-time distributed database is known as Open Telecom Platform, OTP. Ericsson offers commercial support for Erlang.
Since taking the open source path in 1998, it became used by several companies world-wide, including Nortel and T-Mobile. However, it didn't and hasn't yet become a wide-spread mainstream programming language.
As of 2005, Erlang is under active development with regular releases. It is available for several Unix-like operating systems and Microsoft Windows.
Advantages
- superb support for concurrency (it is no problem to create hundreds of thousands of threads)
- high programmer productivity (Ericsson study claim 4x higher than C)
- small and simple to learn: Erlang is not academic language but real-world tool designed to be useable by Ericsson programmers
- scalability: large systems with millions lines of code were written in Erlang
Disadvantages
- not intended for high-performance applications (interpreted language, uses garbage collection)
- lack of static typing: many errors are caught only during runtime (over time the compiler is improved to catch more typing errors, though)
- as it is not a mainstream language there are not many tools, books, libraries or skilled developers. For example GUI support is still in its infancy.
See also
- ejabberd, an instant messaging server written in Erlang.
- Wings 3D, 3D modeller written in Erlang.
- Yet another web server (YAWS, fully featured Web server written in Erlang)
External links
- Erlang white paper (http://www.erlang.org/white_paper.html)
- Open-source implementation (http://www.erlang.org/)
- Mailing Lists and FAQ for the Erlang Community (http://erlang.org/faq.html)
- A collaborative portal for the Erlang community (http://www.erlang-projects.org/)
- Worldwide training and consulting services (http://www.erlang-consulting.com/)
Template:Major programming languages smallde:Erlang (Programmiersprache)
fr:Erlang (langage)
it:Erlang (linguaggio)
nl:Programmeertaal Erlang
ru:Erlang
sv:Erlang