comparison 5-Erlang/translate.erl @ 75:2df568aae515

Add translation example with notes
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Feb 2018 20:12:07 +0000
parents
children
comparison
equal deleted inserted replaced
74:41c7cd909218 75:2df568aae515
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.