# HG changeset patch # User IBBoard # Date 1517689547 0 # Node ID 5860845f5dacdd226053fe06e44b28b6aa232ffc # Parent 2df568aae5157c65a92364f80a9888afee5f4063 Create module with synchronous translation and notes on how to run diff -r 2df568aae515 -r 5860845f5dac 5-Erlang/translate_sync.erl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/5-Erlang/translate_sync.erl Sat Feb 03 20:25:47 2018 +0000 @@ -0,0 +1,25 @@ +-module(translate_sync). +-export([loop/0]). +-export([translate/2]). + +% Invoke with: Pid = spawn(fun translate_sync:loop/0). +% Send messages with: translate_sync:translate(Pid, Word). +% This is sync with no return value. +loop() -> + receive + { Pid, "casa" } -> + Pid ! "house", + loop(); + { Pid, "blanca" } -> + Pid ! "white", + loop(); + { Pid, _ } -> + Pid ! "*blank stare*", + loop() +end. + +translate(To, Word) -> + To ! { self(), Word }, + receive + Translation -> io:format("~s~n", [Translation]) + end. \ No newline at end of file