Mercurial > repos > other > SevenLanguagesInSevenWeeks
changeset 75:2df568aae515
Add translation example with notes
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 03 Feb 2018 20:12:07 +0000 |
parents | 41c7cd909218 |
children | 5860845f5dac |
files | 5-Erlang/translate.erl |
diffstat | 1 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/5-Erlang/translate.erl Sat Feb 03 20:12:07 2018 +0000 @@ -0,0 +1,23 @@ +-module(translate). +-export([loop/0]). + + +% Invoke with: Pid = spawn(fun translate:loop/0). +% Send messages with: Pid ! "message". +% This is async with no return value. +loop() -> + receive + % "receive" is a control structure that defines what "messages" we respond to + "casa" -> + io:format("house~n"), + loop(); % And each entry must make sure that we start the loop again + % If we had a "quit" message then it just wouldn't call loop() + % Because of the way that tail recursion works then calling this last + % has almost no overhead, but doing it in the middle would. + "blanca" -> + io:format("white~n"), + loop(); + _ -> + io:format("*blank stare*~n"), + loop() +end. \ No newline at end of file