75
|
1 -module(translate).
|
|
2 -export([loop/0]).
|
|
3
|
|
4
|
|
5 % Invoke with: Pid = spawn(fun translate:loop/0).
|
|
6 % Send messages with: Pid ! "message".
|
|
7 % This is async with no return value.
|
|
8 loop() ->
|
|
9 receive
|
|
10 % "receive" is a control structure that defines what "messages" we respond to
|
|
11 "casa" ->
|
|
12 io:format("house~n"),
|
|
13 loop(); % And each entry must make sure that we start the loop again
|
|
14 % If we had a "quit" message then it just wouldn't call loop()
|
|
15 % Because of the way that tail recursion works then calling this last
|
|
16 % has almost no overhead, but doing it in the middle would.
|
|
17 "blanca" ->
|
|
18 io:format("white~n"),
|
|
19 loop();
|
|
20 _ ->
|
|
21 io:format("*blank stare*~n"),
|
|
22 loop()
|
|
23 end. |