This document provides an overview of the Erlang programming language. It discusses that Erlang is a general purpose, concurrent, functional programming language developed at Ericsson for building distributed, fault-tolerant systems. It notes some of Erlang's key uses in telecommunications, banking, messaging, and e-commerce where high-availability is required. The document also summarizes that Erlang uses processes instead of threads to enable concurrency, and that it relies on recursion rather than loops for iteration due to its functional nature.
1. Erlang
A concurrent, fault tolerant
programming language developed at Ericsson
PRESENTED BY Yasas Gunarathne
2. What is Erlang?
Erlang is a
❖ General-purpose
❖ Concurrent
❖ Functional
programming language, as well as a
❖ Garbage-collected runtime system.
Wikipedia
3. 1. General Purpose?
Yes, but It has a very special niche, where it performs extremely
well.
➔ Telecommunications and Banking
➔ Instant Messaging
➔ E-Commerce
Where
● Distributed, Fault-tolerant, Soft real-time, Readily
available, non-stopping applications are required.
● Hot-swapping — allows the code to be modified without
stopping the system.
4. 2. Concurrent?
It is easy to create parallel threads of execution in an Erlang
program and to allow these threads to communicate with each
other. In Erlang, each thread of execution is called a process.
➔ Threads of execution in Erlang share no data, that is why
they are called processes
➔ There are no DEAD LOCKS or LIVE LOCKS in ERLANG.
5. 3. Functional?
In a functional language the assignment of a value to a variable is
binding, just as it would be in a mathematical function. In a math
example, we might say: let x = 2. That is to say for this problem, x
is the value of 2.
x = x + 1
Java lambda expression is the Java's first step into functional
programming.
6. Java Lambda Expressions
Event listeners in Java are often defined as Java interfaces with a
single method.
public interface StateChangeListener {
public void onStateChange(State oldState, State newState);
}
In Java 7 we could add an event listener using an anonymous
interface implementation.
7. Java Lambda Expressions
In Java 7 you could add an event listener using an anonymous
interface implementation, like this:
StateOwner stateOwner = new StateOwner();
stateOwner.addStateListener(new StateChangeListener() {
public void onStateChange(State oldState, State newState) {
// do something with the old and new state.
}
});
But in Java 8 we can use lambda expressions...
8. Java Lambda Expressions
StateOwner stateOwner = new StateOwner();
stateOwner.addStateListener(
(oldState, newState) -> System.out.println("State changed")
);
Limitations:
● Does the interface have only one method?
● Does the parameters of the lambda expression match the
parameters of the single method?
● Does the return type of the lambda expression match the
return type of the single method?
9. Erlang Runtime System
Erlang programs are executed when you instruct the Erlang
Runtime System (ERTS) to execute your code. They do not
run as binary programs, which can be executed directly by
your computer. ERTS consists of an Erlang evaluator and
some libraries. The Erlang evaluator is often referred to as an
emulator and is very similar to the Java virtual machine.
10. Built-in Data Types
● Number − In Erlang, there are 2 types of numeric literals which
are integers and floats.
● Atom − An atom is a literal, a constant with name. An atom
is to be enclosed in single quotes (') if it does not begin with a
lower-case letter or if it contains other characters than
alphanumeric characters, underscore (_), or @.
● Boolean
● Bit String − A bit string is used to store an area of un-typed
memory.
● Tuple
● Map
● List
11. Hello World!!
% hello world program
-module(hello_world).
-export([hello/0]).
hello() ->
io:fwrite("Hello, world!n").
1> c(hello_world).
2> hello_world:hello().
Hello, world!
ok
12. Loops!! loop(0) ->
ok;
loop(Count) ->
% do something
loop(Count-1).
Functional
programming
languages don’t offer
any constructs for
loops. Instead, depends
on recursion.
14. Erlang OTP
OTP is a collection of useful middleware, libraries, and tools
written in Erlang programming language.
OTP stands for “Open Telecom Platform”. However neither
Erlang nor OTP is specific to telecom applications.
If you want to program your own applications using OTP,
then the central concept that you will find very useful is the
OTP behavior.