Skip to content

Instantly share code, notes, and snippets.

@noobymatze
Created December 15, 2015 14:58
Show Gist options
  • Save noobymatze/94e2dfaed0016fb14bee to your computer and use it in GitHub Desktop.
Save noobymatze/94e2dfaed0016fb14bee to your computer and use it in GitHub Desktop.
Birthday fun in Erlang
% Usage:
% $ erl
% > c(birthday).
% > Pid = birthday:start().
% > birthday:greet(Pid, "Waschti").
-module(birthday).
-export([start/0, greet/2]).
birthday(Greets) ->
receive
{greet, Name, Pid} ->
[Next|Rest] = Greets,
Greet = lists:flatten(io_lib:format(Next, [Name])),
Pid ! {greeting, Greet},
birthday(lists:append(Rest, [Next]));
_Else ->
exit(nope)
end.
greet(Pid, Name) ->
Pid ! {greet, Name, self()},
receive
{greeting, Greet} ->
Greet
end.
start() ->
Greetings = [ "Herzlichen Glückwunsch zum Geburtstag, ~s!"
, "Alles, alles Gute zu deinem Geburtstag, ~s!"
, "Happy Birthday to youu, Happy birthday to youu ~s!"
],
spawn(fun() -> birthday(Greetings) end).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment