Mercurial > repos > other > SevenLanguagesInSevenWeeks
view 5-Erlang/translate.erl @ 103:98be775c533c default tip
An odd "non-determinism" example from StackOverflow
It is clever, but doesn't make much sense as to how it gets its results
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 14 Jul 2019 13:44:13 +0100 |
parents | 2df568aae515 |
children |
line wrap: on
line source
-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.