Top 1,000 Features Creators Resources Blog Explore Download
GitHub icon

Erlang

< >

Erlang is an open source programming language created in 1986 by Joe Armstrong and Robert Virding and Mike Williams.

#40on PLDB 38Years Old 29kRepos

Try now: Riju

Erlang ( ER-lang) is a general-purpose, concurrent, functional programming language, as well as a garbage-collected runtime system. The term Erlang is used interchangeably with Erlang/OTP, or OTP, which consists of the Erlang runtime system, a number of ready-to-use components mainly written in Erlang, and a set of design principles for Erlang programs. The Erlang runtime system is known for its designs that are well suited for systems with the following characteristics: Distributed Fault-tolerant Soft real-time, Highly available, non-stop applications Hot swapping, where code can be changed without stopping a system. Read more on Wikipedia...


Example from Compiler Explorer:
-module(square). -export([square/1]). square(A) -> A*A.
Example from Riju:
-module(main). -export([main/0]). main() -> io:fwrite("Hello, world!\n").
Example from hello-world:
-module(erlang_hw). -export([start/0]). start() -> io:format("Hello World~n").
%% Hello World in Erlang -module(hello). -export([hello/0]). hello() -> io:format("Hello World!~n", []).
Example from Linguist:
#!/usr/bin/env escript -export([main/1]). main([]) -> io:format("Hello, World!~n").
Example from Wikipedia:
%% Second version -module(counter). -export([start/0, codeswitch/1]). start() -> loop(0). loop(Sum) -> receive {increment, Count} -> loop(Sum+Count); reset -> loop(0); {counter, Pid} -> Pid ! {counter, Sum}, loop(Sum); code_switch -> ?MODULE:codeswitch(Sum) end. codeswitch(Sum) -> loop(Sum).
Erlang Keywords
after and andalso begin bnot bor bsl bsr bxor case catch cond div end fun if let not of or orelse receive rem try when xor

Language features

Feature Supported Token Example
Integers โœ“
% [+-]?(?:[2-9]|[12][0-9]|3[0-6])#[0-9a-zA-Z]+
Floats โœ“
% [+-]?\d+.\d+
Conditionals โœ“
Functions โœ“
Print() Debugging โœ“ io:format
Message Passing โœ“
Line Comments โœ“ %
% A comment
Macros โœ“
-define(Const, Replacement).
-define(Func(Var1,...,VarN), Replacement).
hasExports โœ“
-export([start/0, codeswitch/1]).
File Imports โœ“
-include("my_records.hrl").
-include("incdir/my_records.hrl").
-include("/home/user/proj/my_records.hrl").
-include("$PROJ_ROOT/my_records.hrl").
-include_lib("kernel/include/file.hrl").
Directives โœ“
-define(TIMEOUT, 200).
...
call(Request) ->
   server:call(refserver, Request, ?TIMEOUT).
-undef(Macro).
Comments โœ“
% hello world program
Shebang โœ“
#!/usr/bin/env escript
Strings โœ“
"hello world"
Case Insensitive Identifiers X
Semantic Indentation X
MultiLine Comments X

View source

- Build the next great programming language ยท About ยท Acknowledgements ยท Extensions ยท Day 624 ยท feedback@pldb.io