Thinking in Erlang RIGHT HEADER HERE
Contents
1 Introduction 4
1.1 What this document is not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 What this document is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3 Porting code to Erlang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4 Hello, World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.5 Compiling and running hello.erl . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Scope of variables 7
2.1 No global state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2 Dealing with no global state . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Matching 9
3.1 Basic matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.2 Function argument matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.3 If and case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.4 Guards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 Loops 14
4.1 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.2 Less painful loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.3 Summary of less painful loops . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5 Processes 19
5.1 Doing two things at once . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195.2 Interprocess communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205.3 Process termination reasons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215.4 Processes as objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225.5 Generic servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245.6 Distributed Erlang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.7 Synchronization not necessary . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6 Dealing with errors 26
6.1 Let it fail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266.2 Workers and supervisors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
References 31
3
Add a Comment
Jeremy LeBardleft a comment
autophileleft a comment
abestoleft a comment