Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Erlang (8LU)

Introduction to Erlang (8LU)

Patrick Gombert

March 08, 2013
Tweet

More Decks by Patrick Gombert

Other Decks in Technology

Transcript

  1. - Developed by Ericsson in 1986 - First implementation was

    in Prolog - Later the VM was rewritten in C - Concurrent, fault tolerant with no maintenance downtime - Ericsson AXD301 switch (1998) - 1MLOC with 99.9999999% reliability - Open sourced in 1996 A Brief History Friday, March 8, 13
  2. Language The Language/VM Split Virtual Machine Erlang & Elixir Bogdan/Bjrn's

    Erlang Abstract Machine (BEAM) Java, Scala, & Clojure Java Virtual Machine (JVM) a la... Friday, March 8, 13
  3. Data Types Integer - 42 - No limit in size

    Float - 4.2 - 64bit representation Atom - example - Non garbage collected values Reference - ref - Unique value from make_ref/0 Binary - <<“bin”>> - Sequence of bytes Pid - <0.42.0> - Process ID issued per process Port - #Port<0.592> - Port ID from open_port/2 Fun - #Fun<erl_eval.20.82930912> - First class function Friday, March 8, 13
  4. Collection Types Tuple - {} - Position emphasized structure List

    - [] - List (Head | Tail) String - “str” - A list of character (integer) values Record - #rec{k=v} - A named-key dictionary Friday, March 8, 13
  5. Erlang is not “pure” since it allows for IO without

    monads. Functional Language Single Assignment: Value = value. Value = othervalue. % -> no match exception - This exception happens at runtime Pattern Matched: {LeftHandSide, _} = {value, othervalue}. LeftHandSide. % -> value - Used for all forms of case statements Friday, March 8, 13
  6. There are better strategies to test the limits, but let’s

    skip those for now Take It To The Limit Friday, March 8, 13
  7. Turn It Up To 11 (million) Note: do not do

    this in production Friday, March 8, 13
  8. Scaling Actors - All messages are values - Messages are

    system events across actors - Delivery is guaranteed - Order of messages from one actor to another is guaranteed - Actors share no state Friday, March 8, 13
  9. Economy implemented w/ Actors Pros Cons Non-blocking reads and writes

    (no sychronized sections) No live-lock scenarios like with STM We can wait a long time for our message to process Overhead for knowledge of message completions Friday, March 8, 13
  10. Supervisor hierarchies The main RPL process supervised eval Common for

    main to be the ‘application supervisor’ Worker eval RPL Supervisor Friday, March 8, 13
  11. Idiomatic Erlang Erlangers usually avoid code like the previous example

    Instead, use OTP (which is next week’s topic) Friday, March 8, 13
  12. Homework - Install Erlang on your machine - Fetch and

    run ping of death (make sure it boots) https://github.com/patrickgombert/ping-of-death- client - Feel comfortable solving bite sized problems learn you some erlang http://learnyousomeerlang.com/ koans perhaps? http://github.com/patrickgombert/erlang-koans Friday, March 8, 13