Erlang

863 views

Published on

Published in: Technology
  • uhh.. Erlang is NOT based on Prolog!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Erlang

  1. 1. Erlang – What is it?- created by Joe Armstrong in 1986 at Ericcsson Telecom - based on Prolog - functional language - dynamicly typed Author: Mateusz Zawisza
  2. 2. Where is it used? - RabbitMQ (France Telecom) - Facebook Chat - GitHub (egitd) - SampleDB (AWS) Author: Mateusz Zawisza
  3. 3. Types - variablesVar = 2.Var. %=> 2Var = 3. % this throws an error! Author: Mateusz Zawisza
  4. 4. Types - atoms - same role as symbols in Ruby - usually start with lower-casethis_is_atom Author: Mateusz Zawisza
  5. 5. Types - lists[1, 2, 3, 4] Author: Mateusz Zawisza
  6. 6. Types - tuples{a, 2,"d"}.{ company, {name, "Applicake", {address, "Krakow"} }}. Author: Mateusz Zawisza
  7. 7. MatchingCompany = {company, {name, "Applicake"}, {address, "Krakow"}}.{company, {name, Name}, {address, Address}} = Company.Name %=> "Applicake"Address %=> "Krakow" Author: Mateusz Zawisza
  8. 8. Matching[Head | Tail] = [1,2,3,4].Head. %=> 1Tail. %=> [2,3,4] Author: Mateusz Zawisza
  9. 9. Matching[One, Two | Rest] = [1,2,3,4].One. %=> 1Two. %=> 2Rest.%=> [3,4] Author: Mateusz Zawisza
  10. 10. Functions -module(mirror_function). -export([mirror/1]).mirror(Argument) -> Argument. Author: Mateusz Zawisza
  11. 11. Functions-module(matching_function). -export([number/1]). number(one) -> 1; number(two) -> 2; number(three) -> 3. Author: Mateusz Zawisza
  12. 12. FunctionsNumbers = [1,2,3,4].lists:map(fun(X) -> X+1 end, Numbers).%=> [2,3,4,5] Author: Mateusz Zawisza
  13. 13. Functionsmap(F, [H|T]) -> [F(H) | map(F, T)];map(F, []) -> []. Author: Mateusz Zawisza
  14. 14. Control sturctures... case...case Animal of "dog" -> underdoga; "cat" -> thundercat _ -> something_elseend. Author: Mateusz Zawisza
  15. 15. Control sturctures... if...if X > 0 -> positive; X < 0 -> negative; true -> zeroend. Author: Mateusz Zawisza
  16. 16. ProcessesPid = spawn(fun module_name:function_name/0).Pid ! "message". Author: Mateusz Zawisza
  17. 17. Processesfuction_name() -> receive "message" -> io:format("Hi!"), function_name(); _ -> io:format("Whatever..."), function_name()end. Author: Mateusz Zawisza

×