The Erlang Programming Language
Upcoming SlideShare
Loading in...5
×
 

The Erlang Programming Language

on

  • 4,206 views

http://notdennisbyrne.blogspot.com/2009/09/presenting-erlang-at-polyglot.html

http://notdennisbyrne.blogspot.com/2009/09/presenting-erlang-at-polyglot.html

Statistics

Views

Total Views
4,206
Views on SlideShare
4,188
Embed Views
18

Actions

Likes
3
Downloads
55
Comments
0

3 Embeds 18

http://www.slideshare.net 12
https://www.linkedin.com 4
http://www.linkedin.com 2

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

The Erlang Programming Language The Erlang Programming Language Presentation Transcript

  • Dennis Byrne [email_address]
    • The Erlang Programming Language
  • Introduction
    • Not a “shiny new object (or function)”
    • Open sourced by Ericsson in 1998
    • Functional Programming
    • Concurrency
    • Reliability
    Erlang is a functional programming language, with native constructs for concurrency and reliability.
  • Functions as First Class Citizens
    • Msg = “Lexically scoped closures”,
    • F = fun()-> erlang:display(Msg) end,
    • F(). % prints “ Lexically scoped closures ”
  • Single Assignment & Unification
    • I = 4. % assignment
    • I = I. % unification (invariant)
    • 4 = I. % unification (invariant)
    • I = 5. % throws error
    • MyList = [ “ A ” ].
    • [x] = MyList. % implicit declaration
    • erlang:display(X). % prints “ A ”
  • Tail Recursion
    • loop() ->
    • erlang:display(“in constant space”),
    • loop().
    • Automatic byte code manipulation
    • Runs in constant space
    • Last call optimization
    • for , do and while are the new malloc
    • Tail recursion is to ‘recursion’ as optimistic locking is to ‘locking’
  • Arbitrary Precision
    • Math in Erlang behaves correctly
    • Sum = 1111111111111111111111111111 + 1.
  • Currying, Memoization and Monads
  • What is an Erlang Process?
    • An Erlang process (misnomer) combines the best of
      • An operating system process
      • An operating system thread
      • A “green thread”
    • Controlled in user space by the ERTS
    • Costs less than 300 bytes
      • Private heap
      • Private stack
    • Pre-emptive Scheduling
    • Incremental garbage collection
    • Private immutable state
    Most important slide in this presentation
  • The Actor Model
    • Asynchronous message passing
    • Messages passed by value, not reference
    • One to one relationships
      • An Actor
      • A mailbox
      • A Process
      • A Process ID, or pid
  • Concurrency Primitives: spawn
    • A built in function used to create a process.
    • Pid = spawn(Node, Module, Function, Args)
  • Concurrency Primitives: the send operator
    • !
  • Concurrency Primitives: sending
    • The send operator passes a message to a process.
    • It is “fire and forget”.
    • Msg = { 4, true, “B” },
    • Pid ! Msg.
  • Concurrency Primitives: receive
    • receive
    • Pattern1 [ when Guard1 ] ->
    • dosomething().
    • Pattern2 [ when Guard2 ] ->
    • dosomethingelse().
    • end
  • Reliability
    • Open Telecom Platform - Supervisor Trees
    • Monitor
      • monitor_node(Node, Bool)
      • Unidirectional
    • Link
      • Pid = spawn_link(Node, Module, Fun, Args)
      • Bi-directional
    • Sequential Constructs
      • try
      • catch
  • Reliability (Continued)
    • Erlang can run two and only two versions of a module
    • Code running has a version lifecycle
      • Current
      • Old
      • Dead
    • Function definitions can be upgraded in the middle of a tail recursive call
    • This VM could do this before closures were supported
    • Ericsson claims nine nines uptime on AX3D01
      • 2 million lines of Erlang
      • Five nines = 5.2 minutes of downtime/year
  • Open Telecom Platform Behaviours
    • Basic Design Principles
      • Interface
      • Design Pattern
    • Supervision Trees
    • Generic Servers
    • Finite State Machines
    • Event Manager
  • Supervisor Behaviour
    • -module(byrne_sup).
    • -behaviour(supervisor).
    • -export([start_link/1, init/1]).
    • start_link(Args) ->
    • supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
    • init(_Args) ->
    • {ok, {{one_for_one, 10, 10},
    • [{byrne, {byrne, start_link, []},
    • permanent, 2000, worker, [byrne]}]}}.
  • Generic Server Behaviour (abbreviated)
    • -module(byrne).
    • -behaviour(gen_server).
    • start_link() ->
    • gen_server:start_link({local, ?MODULE}, ?MODULE, self(), []).
    • handle_call(Function, _From, State) ->
    • {reply, erlang:apply(rest, Function, []),, State + 1}.
    • handle_cast(_Msg, State) ->
    • {noreply, State}.
  • The Erlang Programming Language
    • Thanks
    • Dennis Byrne – DRW Trading
    • [email_address]