Frontier Software

Concurrency Oriented Programming

Here I’m going to switch from translating examples in K&R to translating examples from another classic, Joe Armstrong’s Programming Erlang: Software for a Concurrent World.

I put some notes on Erlang at github:

Erlang has no mutexes, no synchronized methods, and none of the paraphernalia of shared memory programming. — Joe Armstrong

While Go has those things, programers are encouraged to do things Erlang-style.

Do not communicate by sharing memory; instead, share memory by communicating. — Effective Go

Processes interact by one method, and one method only, by exchanging messages. — Joe Armstrong

Here’s the traditional starting example written in Erlang.

-module(hello).
-export([start/0]).

start() ->
    io:format("Hello world~n").

This in a file hello.erl and module names are required to be the filename without the .erl suffix. Go uses title-case names in lieu of Erlang’s functor list export declaration, whereas Erlang follows the Prolog convention of title-case variable names that cannot be given new values once unified. An Erlang convention is to call the equivalent of a C/Go main() function start(), but it’ not enforced.