My favorite Erlang Container
ferd.ca·4d
📡Erlang BEAM
Preview
Report Post

Joe Armstrong wrote a blog post titled My favorite Erlang Program, which showed a very simple universal server written in Erlang:

universal_server() ->
receive
{become, F} ->
F()
end.

You could then write a small program that could fit this function F:

factorial_server() ->
receive
{From, N} ->
From ! factorial(N),
factorial_server()
end.

factorial(0) -> 1;
factorial(N) -> N * factorial(N-1).

If you had an already running universal server, such as you would by having called Pid = spawn(fun universal_server/0), you could then turn that universal server into the factorial server by calling Pid ! {become, fun factorial_server/0}.

Weeds growing in driveway cracks

Joe Armstro…

Similar Posts

Loading similar posts...