Generated by DeepSeek V3.2| Erlang (programming language) | |
|---|---|
| Name | Erlang |
| Paradigm | Functional, concurrent, distributed |
| Designer | Joe Armstrong, Robert Virding, Mike Williams |
| Developer | Ericsson |
| Latest release version | OTP 27 |
| Latest release date | May 2024 |
| Typing | Dynamic, strong |
| Influenced by | Prolog, Smalltalk, ML |
| Influenced | Elixir, Scala, Akka |
| Operating system | Cross-platform |
| License | Apache License 2.0 |
Erlang (programming language). Erlang is a general-purpose, concurrent, functional programming language and a runtime environment developed by the Ericsson Computer Science Laboratory. It was designed from the ground up for building highly available, fault-tolerant systems with requirements for massive scalability and continuous operation, such as telecommunication switches. The language is known for its lightweight process model, message-passing concurrency, and support for hot code swapping, making it a foundational technology for the Open Telecom Platform (OTP) framework.
The development of Erlang began in the mid-1980s at the Ericsson lab in Älvsjö, Stockholm, by a team including Joe Armstrong, Robert Virding, and Mike Williams. The initial goal was to find a better way to program the next generation of telephone exchanges, which required extreme reliability. Early prototypes were influenced by languages like Prolog and experimented with concurrent ML. After proving its value in projects like the AXE-N project, Erlang was released as open source in 1998, leading to the formation of the OTP team. The language's stewardship later moved to the Ericsson-sponsored Erlang Solutions and the open-source community, with major releases managed by the Erlang/OTP team at Ericsson.
Erlang's core design principles are centered on building systems that "never stop". It embraces the actor model of concurrency, where isolated processes communicate solely via asynchronous message passing. The language is built on a "let it crash" philosophy, advocating for lightweight supervisors to manage process failures rather than defensive in-process error checking. Other key principles include shared-nothing architecture between processes, location transparency for distributed computing, and support for dynamic software upgrading in running systems, a necessity for systems requiring "five nines" availability.
As a functional language, Erlang emphasizes immutable data structures, first-class functions, and single assignment variables. It employs pattern matching as a primary control structure for binding variables and selecting code paths. List comprehensions provide a concise syntax for generating and transforming lists. While not purely functional due to side effects like message passing, it encourages a functional style within processes. The language lacks traditional loop constructs, relying instead on recursion and higher-order functions like those found in the ML family.
Concurrency is intrinsic to Erlang, implemented via ultra-lightweight processes that are scheduled by the BEAM virtual machine, not the operating system. Millions of these processes can run concurrently, each with isolated garbage collection. Communication uses copy semantics message passing with mailboxes. Distribution is seamless; a process on one node can communicate with a process on another as if they were local, facilitated by the Erlang Distribution Protocol. Built-in primitives like `spawn`, `send` (`!`), and `receive` underpin this model, which is foundational to frameworks like Akka for the JVM.
Erlang's primary use case remains high-concurrency, low-latency, distributed backend systems. It is famously used in the core infrastructure of WhatsApp, Ericsson's own telecom gear, and the RabbitMQ messaging broker. The gaming industry employs it for MMO server backends, such as those for League of Legends. It is also used in fintech for high-frequency trading platforms, in blockchain implementations like Cardano, and in databases such as CouchDB and Riak. The Elixir language, which runs on the BEAM, has further expanded its ecosystem into web development with the Phoenix framework.
Erlang syntax is influenced by Prolog, using a comma (`,`) as a separator, semicolon (`;`) for clause separation, and period (`.`) to terminate statements. Variables begin with an uppercase letter (e.g., `List`), while atoms (constants) are lowercase (e.g., `ok`). Pattern matching is ubiquitous: `{X, Y} = {10, 20}` binds `X` to `10`. A simple function using recursion to calculate a factorial is: ``` -module(math). -export([fact/1]).
fact(0) -> 1; fact(N) when N > 0 -> N * fact(N-1). ``` A concurrent example spawning a process to echo a message: ``` Pid = spawn(fun() -> receive Msg -> io:format("Got ~p~n", [Msg]) end end), Pid ! hello. ```
Category:Programming languages Category:Functional programming languages Category:Concurrent programming languages