The languages FRACTRAN and Chef use metaphors/systems from outside programming to very different effect. FRACTRAN, created by John Conway, represents algorithms as a list of fractions, a translation of code into rational numbers. Chef, by David Morgan-Mar, represents code as a cooking recipe. These two languages encapsulate the two types of esolangs explored in Part 1; FRACTRAN remains entirely within the logical sphere (a “behavior-oriented language”). At first, the idea of recipes may sound similar – recipes can be thought of as a type of recipe for the computer – Chef uses its system to complicate the logical space, bringing in aspects of natural languages drawn from food preparation into the code. This is what we’d described as vocabulary-based.

How they work:

Chef’s recipes begin with a list of ingredients, then a list of instructions, usually culminating with baking time. In Chef, the ingredients hold individual data values. Cooking time and baking temperature are optional. The heart of the program is in the cooking method, which are step-by-step instructions, often involving excessive use of mixing bowls (which refer to the stack). 

We can think of Chef as a simple cypher that hides a program in plain sight. The recipe is both the program and a parallel narrative to the program, adding additional information irrelevant to making its code run. Chef programming style encourages names meaningful to the recipe, not the code it represents (ingredients/variables like chicken and sugar, instead of x and y). Chef is a metaphor, but one that we can physically enact; a material mapping.

Lobsters with Fruit and Nuts.

This recipe prints "Hello, World!" in a most delicious way.

72 g hazelnuts
101 eggs
108 g lobsters
111 ml orange juice
44 g cashews
32 g sugar
87 ml water
114 g rice
100 g durian
33 passion fruit
10 ml lemon juice

Put lemon juice into the mixing bowl.
Put passion fruit into the mixing bowl.
Put durian into the mixing bowl.
Put lobsters into the mixing bowl.
Put rice into the mixing bowl.
Put orange juice  into the mixing bowl.
Put water into the mixing bowl.
Put sugar into the mixing bowl.
Put cashews into the mixing bowl.
Put orange juice into the mixing bowl.
Put lobsters into the mixing bowl.
Put lobsters into the mixing bowl.
Put eggs into the mixing bowl.
Put hazelnuts into the mixing bowl.
Liquify contents of the mixing bowl.
Pour contents of the mixing bowl into the baking dish.

Serves 1.

FRACTRAN is very different. There are no flourishes, and the system it uses as a parallel for code is actually used in the execution of that code. A FRACTRAN program is a series of fractions, to be carried out on an integer (n) passed in. This is the formula for primes in FRACTRAN (from Wikipedia):

1. for the first fraction f in the list for which nf is an integer, replace n by nf
2. repeat this rule until no fraction in the list produces an integer when multiplied by n, then halt.

To get a sense of how it works, this Fractran program (of a single fraction) adds from one register to another:


We read this by determining that the numerator’s prime factorization is 5 ^ 2 and the denominator’s is 3 ^ 2. In FRACTRAN, each register is a prime number; the data held in that register is its exponent. In this program, we deal with registers 3 and 5. To run the program on a given input (a rational number), we factorize the input; does it have 3 as a factor? With what exponent? If it is a multiple of three, and its r3 has at least 2 in it (it can be evenly divided by 9), we subtract two from r3 and then add two to r5, and then we’re done; we’ve executed the code. That’s the whole of this program. 

The important take-away is that this series operations we carry out *is* the algorithm. This is the beauty of the language; nothing feels arbitrary. Its system of computation is based on simple principles – easy to understand in theory, even if confusing to use. There is no loss or gain of information translating between the two systems – while, for Chef, the excess of information is the key to it as a work. 

But what if we were to actually execute the recipe for a Hello, World cake in Chef? There is at least one actual edible Chef program out there; the Hello, World cake by Mike Worth. The cake is an assemblage of instructions for the program made edible, the excess of the recipe metaphor taken to its logical result. 

Mike Worth, first step of Hello, World cake

But why bring together such an odd pair as cooking and code, and why carry that system past the point where the recipe holds meaning as code? One idea comes from Erst Cassirer. According to his Language and Myth, rational thought evolved from speech when it became understood that signs (linguistic or otherwise) are arbitrary, allowing us to work with them as abstractions. If the words for “stone” and “man” are assonant (as they were in Ancient Greek), we now understand that to be coincidence, not a sign that humans were created from stone. In the mythic stage of cultural development, however, words (and other symbols) had a more complex relationship with their referents. Lightning is a serpent because it is serpentine: metaphors hold a literal truth about to what they refer. The resonance between mythological and rational realms of language is at play in languages like Chef. From the rational point of view, the Hello, World! cake is an odd byproduct of a system designed to do something else. But its humor comes from a mythological view: as if, like executing the FRACTRAN instructions in the math space, baking the actual cake could somehow contain the program it was created from. It is an extension of the excess already inherent in the language itself.

For more about FRACTRAN, podsnap has a Clojure implementation and a nice intro to the language. Also, there’s a nice explanation on Good Math, Bad Math.

I interviewed David Morgan-Mar, creator of Chef for this blog.