# HG changeset patch # User IBBoard # Date 1517688727 0 # Node ID 2df568aae5157c65a92364f80a9888afee5f4063 # Parent 41c7cd90921893ca974ed2f2485bdafff5c4d238 Add translation example with notes diff -r 41c7cd909218 -r 2df568aae515 5-Erlang/translate.erl --- /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