changeset 76:5860845f5dac

Create module with synchronous translation and notes on how to run
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Feb 2018 20:25:47 +0000
parents 2df568aae515
children 7bab4843aec6
files 5-Erlang/translate_sync.erl
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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