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.
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.
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!