Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Happy Birthday Ada Lovelace
--
-- Is there a better way to celebrate ones birthday than
-- generating an Ascii cake and some text-output wishin
-- happy birthday to the person I consider one of the most
-- important person in the history of automated computation.
--
-- Note:
-- Compile with gcc after having installed GNAT (If on OSX)
-- $> gcc -c happybirthdayadatask.adb
-- $> gnatbl -o happybirthday happybirthdayadatask.ali
-- $> ./happybirthday
--
-- Author: David Coallier (@davidcoallier)
--
with Ada.Text_Io;
with Ada.Strings.Bounded;
procedure HappyBirthdayAdaTask is
package Inner_Message is new
Ada.Strings.Bounded.Generic_Bounded_Length(400);
use Inner_Message;
--
-- We have the celebrator
-- which are going to be wishing happy birthday
-- with one method called Start which is delayed
task type Celebrator is
entry Start(Message: in String);
end Celebrator;
--
-- And then we have a chef that cooks the
-- cake and gives it to Ada!
--
task type Chef is
entry Cook(Message: in String);
end Chef;
--
-- As Ada was a countess, she's very likely
-- to have had some minions, servants, etc.
-- that's why we use one to light candles.
--
task type Minion is
entry LightCandles(Message: in String);
end Minion;
--
-- People in the partay singing happy birthday
-- to our lovely and loved Countess Lovelace
--
task body Celebrator is
Cheer: Bounded_String;
begin
accept Start(Message: in String)
do
Cheer := To_Bounded_String(Message);
end Start;
-- Delay to let time to breath
delay Duration(3);
Ada.Text_Io.Put_Line(To_String(Cheer));
end Celebrator;
--
-- The chef is doing the cooking ok so hold on!
--
task body Chef is
Dough: Bounded_String;
begin
accept Cook(Message: in String)
do
Dough := To_Bounded_String(Message);
end Cook;
delay Duration(2);
Ada.Text_Io.Put_Line(To_string(Dough));
end Chef;
--
-- A minion lights the candles...
--
task body Minion is
Action: Bounded_String;
begin
accept LightCandles(Message: in String)
do
Action := To_Bounded_String(Message);
end LightCandles;
Ada.Text_Io.Put_Line(To_string(Action));
end Minion;
Happy: Celebrator;
Birthday: Celebrator;
AdaLovelace: Celebrator;
Servant: Minion;
Cake: Chef;
begin
Happy.Start("Happy");
Birthday.Start("Birthday");
AdaLovelace.Start("Ada Lovelace!");
Servant.LightCandles("The servant is now lighting the candles...");
Cake.Cook("" & ASCII.LF
&" iiiiiiiiiii " & ASCII.LF
&" |:H:a:p:p:y:| " & ASCII.LF
&" __|___________|__ " & ASCII.LF
&" |^^^^^^^^^^^^^^^^^| " & ASCII.LF
&" |:B:i:r:t:h:d:a:y:| " & ASCII.LF
&" | | " & ASCII.LF
&" ~~~~~~~~~~~~~~~~~~~");
end HappyBirthdayAdaTask;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment