I am trying to learn erlang. Here's a basic server which calculates area of square. It is a modified version of example 6 of the erlang white paper
Here is the code:
-module(area_server).
-export([start/0, loop/0]).
start() ->
spawn(area_server, loop, []).
loop() ->
receive
{Client, {square, X}} ->
Client ! X*X,
loop()
end.
The problem I have is that it seems I can bind X to only one value. Binding to any other value does not work. To test, I have the following code:
Server = area_server:start().
%Works and returns 100
Server ! {self(), {square, 10}}, receive Area -> Area end.
%Does not work and just does not return at all
Server ! {self(), {square, 5}}, receive Area -> Area end.
So how can I calculate square of 5?