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:

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.