Erlang

453 views
389 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
453
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Erlang

  1. 1. Erlang
  2. 2. What is it?created by Joe Armstrong in 1986 at Ericcsson Telecombased on Prologfunctional languagedynamicly typed
  3. 3. Erlang is...reliablehigh concurrent (no threads. light processes)modular
  4. 4. Where is it used?RabbitMQ (France telecom)CouchDBFacebook ChatGitHub (egitd)SimpleDB (AWS)
  5. 5. Types
  6. 6. VariablesVar = 2.Var.%=> 2Var = 3. % this throws an error!
  7. 7. atomsthis_is_atom
  8. 8. Lists[1,2,3,4]
  9. 9. Tuples{a, 2,"d"}.{ company, {name, "Applicake", {address, "Krakow"}}}.
  10. 10. MatchingCompany = {company, {name, "Applicake"}, {address, "Krakow"} }.{company, {name, Name, {address, Address}}} = Company.Name %=> "Applicake"Address %=> "Krakow"
  11. 11. Matching[Head | Tail] = [1,2,3,4].Head. %=> 1Tail. %=> [2,3,4]
  12. 12. Matching[One, Two | Rest] = [1,2,3,4].One. %=> 1Two. %=> 2Rest.%=> [3,4]
  13. 13. functions-module(mirror_function).-export([mirror/1]).mirror(Argument) -> Argument.
  14. 14. functions-module(matching_function).-export([number/1]).number(one) -> 1;number(two) -> 2;number(three) -> 3.
  15. 15. functionsNumbers = [1,2,3,4].lists:map(fun(X) -> X+1 end, Numbers).%=> [2,3,4,5]
  16. 16. functionsmap(F, [H|T]) -> [F(H) | map(F, T)];map(F, []) -> [].
  17. 17. Control structures case...case Animal of "dog" -> underdoga; "cat" -> thundercat _ -> something_elseend.
  18. 18. Control structures if...if X > 0 -> positive; X < 0 -> negative; true -> zeroend.
  19. 19. Processes
  20. 20. ProcessesPid = spawn(fun module_name:function_name/0).Pid ! "message".
  21. 21. Processesfuction_name() -> receive "message" -> io::format("Hi!"), function_name(); _ -> io::format("Whatever..."), function_name()end.

×