Home >Technology >Erlang Message Passing Concurrency, For The Win

Erlang Message Passing Concurrency, For The Win

Date post:25-Jan-2015
Category:
View:7,517 times
Download:1 times
Share this document with a friend
Description:
 
Transcript:
  • 1. Erlang Message Passing Concurrency, For The Win Toby DiPasquale Commerce360, Inc.Presented to Philly Linux Users GroupJune 6, 2007

2. Er-what?Language/runtime created at Ericsson Designed for scalable, long-lived systems Not object oriented Compiled, Functional, Dynamically typed, Open source 3. Another f*****language?Pattern matchingMessage-passing concurrencyDistributed programmingHot code update 4. Runway ModelsMeeboSlideAwareRabbitMQJabber.orgOpenPoker 5. Sequential 6. =Not what you think it is, Performs a binding Invokes pattern matching, Pattern matching like Prolog, nevermind Perl regexs 7. Syntax Variables start with uppercase letterVariables can only be assigned onceLast evaluation is return value of function Functions and shell exprs end in period Clauses end in semicolon 8. Shes got the look -module(math_o_matics). -export([square/1]).square(X) -> X * X. 9. AtomsSelf-indicating identiersStart with lowercase letterCan also be quoted with single quotes atom this_is_an_atom I am also an atom Used just like youd use an enum in C or a Symbol in Lisp or Ruby 10. Tuples Fixed length containersOften prepended with an identier atomDecompose with pattern matchingCar = {car, {honda, civic}, {horsepower, 100}}.{car, Type, Power} = Car. 11. Lists Variable length containersUse [H|T] syntax to get head and tail of list List = [1, 2, 3, four, 5.0] [Head|Tail] = List [H1,H2|T2] = ListUse lists just like you would in Lisp Do something to head, recursively; [H|T] syntax is pattern matching 12. Strings Not reallyStrings are just lists of integersMust use double quotesMeeting = PLUG. Meeting2 = [80,76,85,71]. Those two examples at the bottom are the same string; String handling blows in Erlang No Unicode 13. ArityUse functions with same name and differentarity* as auxiliary functions-module(math_o_matics). -export([sum/1]).sum(L)-> sum(L, 0). sum([], N)-> N; sum([H|T], N) -> sum(T, H+N).* Arity refers to the number of input parameters a function takes 14. ModulesLogically associated code blockUse colon (:) to use intermodule codeUse -import to avoid prexingio:format(Using the module io~n). One module per le 15. The fun in functional Anonymous functions Used for higher-order programmingSquare = fun(X) -> X * X end.Cube = fun(X) -> Square(X) * X end. 16. List Comprehensions Takes an expression and a set of qualiers and returns another list (like Pythons)Looks like: [X || Q1, Q2, ... Qn ]qsort([]) -> []; qsort([Pivot|T]) -> qsort([X || X Y -> X;max(X, Y) -> Y. Multiple guards separated by a semicolon; Other guards include: arithmetic exprs, short-circuit boolean exprs, constants (False), true (True) 18. Biting the bits Syntax for extracting/packing bits

Click here to load reader

Embed Size (px)
Recommended