Dennis Byrne [email_address] <ul><li>The Erlang Programming Language </li></ul>
Introduction <ul><li>Not a “shiny new object (or function)” </li></ul><ul><li>Open sourced by Ericsson in 1998 </li></ul><...
Functions as First Class Citizens <ul><li>Msg = “Lexically scoped closures”, </li></ul><ul><li>F = fun()-> erlang:display(...
Single Assignment & Unification <ul><li>I = 4.  % assignment </li></ul><ul><li>I = I.  % unification (invariant) </li></ul...
Tail Recursion <ul><li>loop() -> </li></ul><ul><li>erlang:display(“in constant space”), </li></ul><ul><li>  loop(). </li><...
Arbitrary Precision <ul><li>Math in Erlang behaves  correctly </li></ul><ul><li>Sum = 1111111111111111111111111111 + 1. </...
Currying, Memoization and Monads
What is an Erlang Process? <ul><li>An Erlang process (misnomer) combines the best of </li></ul><ul><ul><li>An operating sy...
The Actor Model <ul><li>Asynchronous message passing </li></ul><ul><li>Messages passed by value, not reference </li></ul><...
Concurrency Primitives: spawn <ul><li>A built in function used to create a process. </li></ul><ul><li>Pid = spawn(Node, Mo...
Concurrency Primitives: the send operator <ul><li>! </li></ul>
Concurrency Primitives: sending <ul><li>The send operator passes a message to a process.  </li></ul><ul><li>It is “fire an...
Concurrency Primitives: receive <ul><li>receive </li></ul><ul><li>Pattern1 [ when Guard1 ] -> </li></ul><ul><li>dosomethin...
Reliability <ul><li>Open Telecom Platform - Supervisor Trees </li></ul><ul><li>Monitor </li></ul><ul><ul><li>monitor_node(...
Reliability (Continued) <ul><li>Erlang can run two and only two versions of a module </li></ul><ul><li>Code running has a ...
Open Telecom Platform Behaviours <ul><li>Basic Design Principles </li></ul><ul><ul><li>Interface </li></ul></ul><ul><ul><l...
Supervisor Behaviour <ul><li>-module(byrne_sup). </li></ul><ul><li>-behaviour(supervisor). </li></ul><ul><li>-export([star...
Generic Server Behaviour (abbreviated) <ul><li>-module(byrne). </li></ul><ul><li>-behaviour(gen_server). </li></ul><ul><li...
The Erlang Programming Language <ul><li>Thanks </li></ul><ul><li>Dennis Byrne – DRW Trading </li></ul><ul><li>[email_addre...
Upcoming SlideShare
Loading in...5
×

The Erlang Programming Language

3,064

Published on

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

Published in: Technology, News & Politics

Transcript of "The Erlang Programming Language"

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

    Clipping is a handy way to collect important slides you want to go back to later.

×