Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

37 lines (30 sloc) 0.719 kb
-module(add_subtract).
-export([add/2, subtract/2, init/0]).
init() ->
Pid = spawn(fun() -> loop() end),
global:register_name(add_subtract, Pid).
loop() ->
receive
{add, Augend, Addend, Sender} ->
Sender ! {result, Augend + Addend},
loop();
{subtract, Minuend, Subtrahend, Sender} ->
Sender ! {result, Minuend - Subtrahend},
loop();
stop ->
stop()
end.
stop() ->
ok.
add(Augend, Addend) ->
global:send(add_subtract, {add, Augend, Addend, self()}),
receive
{result, Result} ->
Result
end.
subtract(Minuend, Subtrahend) ->
global:send(add_subtract, {subtract, Minuend, Subtrahend, self()}),
receive
{result, Result} ->
Result
end.
Jump to Line
Something went wrong with that request. Please try again.