September 2013
Intermediate to advanced
548 pages
12h 25m
English
The Erlang view of the world is that everything is a process and that processes can interact only by exchanging messages. Having such a view of the world imposes conceptual integrity on our designs, making them easier to understand.
Imagine we want to write a web server in Erlang. A user
requests a page called hello.html
from our web server. The simplest possible web server
looks like this:
| | web_server(Client) -> |
| | receive |
| | {Client, {get, Page}} -> |
| | case file:read(Page) of |
| | {ok, Bin} -> |
| | Client ! {self(), {data, Bin}}; |
| | {error, _} -> |
| | Client ! {self(), error} |
| | end, |
| | web_server(Client) |
| | end. |
But this code is simple only because all it does is receive and send Erlang terms. But clients ...
Read now
Unlock full access