Baking a Hello World Cake

I have a soft spot for esoteric programming languages. They are (usually) perfectly functional languages, in the rather loose sense that they are Turing complete and thus capable of solving all the same problems as any other language; they do, however, function in an intentionally roundabout way. They include several types: those that minimise the instructions possible such that everything must be spelt out in the simplest possible terms, those that intentionally obfuscate in a parody of ‘real’ languages, and those that aim to represent the program as some other set of instructions; this is the class into which a language called chef falls.

The full specifications are here, however the general idea is to make the program look as much like a recipe as possible. Variables are ingredients, stacks are mixing bowls, input comes via the fridge, output goes via baking dishes and so on. The specification explicitly requires that “Program recipes should not only generate valid output, but be easy to prepare and delicious.”.

There are several example programs provided; they do generate valid output, but fall short on the other two counts. Hello World SoufflĂ© consists of 6 gallons of oil combined with a hundred eggs, various vegetables and some other bits and bobs; the ingredients are put in a mixing bowl, liquefied and served (for one person). I’m guessing that this wouldn’t be particularly appetising, not to mention the negligible chance of finding the ingredients in even a well stocked kitchen.

I decided to come up with a replacement Hello World recipe that would closer meet these requirements; it turned out to be a little more difficult that I first imagined. The particular instruction set offered by chef makes things tricky in several ways:

  • ASCII output must be liquid; this meant that I either had to use all liquid ingredients, or ‘Liquefy’ them at some point before serving. In order to work around this I have taken liquefy to mean either melt or blend, depending on the context.
  • Almost every character code is around 100; this means that a similar quantity of each ingredient must be used if excessive processing is to be avoided. I’ve worked around this by unnecessarily (in a culinary sense) using multiple ingredients where one would do (milk and dark chocolate for example)
  • Each character is an ingredient; this restricts the minimum number of ingredients that the recipe uses. Making an additional sauce allowed me to include extra ingredients, as did adding things like chocolate chips and cocoa powder.
  • The “Serves” statement handles output, leading to needing a either a greedy person or lots of mixing bowls. I worked around this by using the alternative “refrigerate” statement and neglecting to state how many people the recipe serves; this works fairly well for a cake.

After some tinkering I created hello world cake with chocolate sauce:

Hello World Cake with Chocolate sauce.

This prints hello world, while being tastier than Hello World Souffle. The main
chef makes a " world!" cake, which he puts in the baking dish. When he gets the
sous chef to make the "Hello" chocolate sauce, it gets put into the baking dish
and then the whole thing is printed when he refrigerates the sauce. When
actually cooking, I'm interpreting the chocolate sauce baking dish to be
separate from the cake one and Liquify to mean either melt or blend depending on
context.

Ingredients.
33 g chocolate chips
100 g butter
54 ml double cream
2 pinches baking powder
114 g sugar
111 ml beaten eggs
119 g flour
32 g cocoa powder
0 g cake mixture

Cooking time: 25 minutes.

Pre-heat oven to 180 degrees Celsius.

Method.
Put chocolate chips into the mixing bowl.
Put butter into the mixing bowl.
Put sugar into the mixing bowl.
Put beaten eggs into the mixing bowl.
Put flour into the mixing bowl.
Put baking powder into the mixing bowl.
Put cocoa  powder into the mixing bowl.
Stir the mixing bowl for 1 minute.
Combine double cream into the mixing bowl.
Stir the mixing bowl for 4 minutes.
Liquify the contents of the mixing bowl.
Pour contents of the mixing bowl into the baking dish.
bake the cake mixture.
Wait until baked.
Serve with chocolate sauce.

chocolate sauce.

Ingredients.
111 g sugar
108 ml hot water
108 ml heated double cream
101 g dark chocolate
72 g milk chocolate

Method.
Clean the mixing bowl.
Put sugar into the mixing bowl.
Put hot water into the mixing bowl.
Put heated double cream into the mixing bowl.
dissolve the sugar.
agitate the sugar until dissolved.
Liquify the dark chocolate.
Put dark chocolate into the mixing bowl.
Liquify the milk chocolate.
Put milk chocolate into the mixing bowl.
Liquify contents of the mixing bowl.
Pour contents of the mixing bowl into the baking dish.
Refrigerate for 1 hour.

Running it with an interpreter correctly outputs “Hello world!”, while it also looks like a vaguely reasonable cake recipe (the feel of having been through a crappy translator several times notwithstanding). While looking vaguely reasonable is a good start, it isn’t really good enough. I had to actually see what a hello world cake with chocolate sauce tasted like.

It started off with measuring out a bunch of ingredients and putting them into the mixing bowl:
Most of the ingredients in the mixing bowl.

After stirring for a minute, I had to “combine” the cream; I took this to mean pour it in while stirring:
The cream being combined into the mixing bowl

After 4 minutes of stirring it resembled a cake mixture, although there were still a few lumps of butter. The next step of “liquefying” the contents of the mixing bowl fixed this.
The mixture being liquefied

I interpreted “baking dish” as a cake tin, and put the cake into the oven that I’d earlier preheated.
The mixture being put into the oven

While the cake was in the oven, I made the sauce. The first step was to put the sugar into the mixing bowl, followed by hot water and cream (which I heated in the microwave).
The cream being poured into the bowl

I then agitated it until the sugar dissolved.
Agitating the sugar

Next I had to “liquefy” the chocolate and add it; this time I took liquefy to mean melt. I melted both types of chocolate and added them to the mixing bowl.
All the sauce ingredients in the bowl

Back to interpreting “liquefy” as “blend”:
The sauce being "liquefied"

I blended it until it was homogeneous; what I had tasted like chocolate sauce, but was worryingly thin. Nevertheless I poured it into a dish and stuck it in the fridge.
The sauce being put in the fridge

I took the cake out of the oven and, after checking it was cooked through with a skewer, put it onto a cooling rack.
The cake cooling on a rack

The following morning, after eventually explaining to my somewhat bemused family why the cake was a computer program (without a huge amount of success), I got them to help taste it. The sauce had thickened up nicely in the fridge, it was easily served with a spoon and sat on the cake nicely rather than soaking in.
A slice of hello world cake, served with chocolate sauce

It was surprisingly well received; the cake was slightly dry (although nowhere near as dry as cheap supermarket cakes), but this was complimented well by the sauce. My brother even asked me for the recipe!

5 thoughts on “Baking a Hello World Cake

  1. Pingback: Lazy Reading for 2013/04/07 – DragonFly BSD Digest

  2. Pingback: Epic win - Page 196 - London Fixed-gear and Single-speed

  3. Pingback: Keynote at OSDC.tw: What Beginners Teach Us

Leave a Reply