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

Like this? Share it with your network

Share

The Erlang Programming Language

  • 4,316 views
Uploaded on

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

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

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,316
On Slideshare
4,298
From Embeds
18
Number of Embeds
3

Actions

Shares
Downloads
57
Comments
0
Likes
4

Embeds 18

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

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Dennis Byrne [email_address]
    • The Erlang Programming Language
  • 2. 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.
  • 3. Functions as First Class Citizens
    • Msg = “Lexically scoped closures”,
    • F = fun()-> erlang:display(Msg) end,
    • F(). % prints “ Lexically scoped closures ”
  • 4. 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 ”
  • 5. 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’
  • 6. Arbitrary Precision
    • Math in Erlang behaves correctly
    • Sum = 1111111111111111111111111111 + 1.
  • 7. Currying, Memoization and Monads
  • 8. 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
  • 9. 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
  • 10. Concurrency Primitives: spawn
    • A built in function used to create a process.
    • Pid = spawn(Node, Module, Function, Args)
  • 11. Concurrency Primitives: the send operator
    • !
  • 12. Concurrency Primitives: sending
    • The send operator passes a message to a process.
    • It is “fire and forget”.
    • Msg = { 4, true, “B” },
    • Pid ! Msg.
  • 13. Concurrency Primitives: receive
    • receive
    • Pattern1 [ when Guard1 ] ->
    • dosomething().
    • Pattern2 [ when Guard2 ] ->
    • dosomethingelse().
    • end
  • 14. 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
  • 15. 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
  • 16. Open Telecom Platform Behaviours
    • Basic Design Principles
      • Interface
      • Design Pattern
    • Supervision Trees
    • Generic Servers
    • Finite State Machines
    • Event Manager
  • 17. 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]}]}}.
  • 18. 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}.
  • 19. The Erlang Programming Language
    • Thanks
    • Dennis Byrne – DRW Trading
    • [email_address]