Modeling Concurrency

We’ll start with a simple example and build a concurrent model of an everyday scene. Imagine I see four people out for a walk. There are two dogs and a large number of rabbits. The people are talking to each other, and the dogs want to chase the rabbits.

To simulate this in Erlang, we’d make four modules called person, dog, rabbit, and world. The code for person would be in a file called person.erl and might look something like this:

 
-module​(person).
 
-export​([init/1]).
 
 
init(Name) -> ...

The first line, -module(person)., says that this file contains code for the module called person. This should be the same as the filename (excluding the .erl filename extension). The module name must start with a small letter. ...

Get Programming Erlang, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.