Chef
Created | Updated Jul 5, 2011
Chef is an esoteric programming language. Programmes written in Chef look like cooking recipes, which is the reason for its classification as esolang.
Like some other innovative esolangs, Chef was created by David Morgan-Mar. It is considered to pursue similar design guidelines as SPL - both languages' code looks like something completely different, but surely not like computer stuff.
Chef operates on stacks. In computer science, a stack is a data structure that can hold several values in a specific order. The last value pushed on the stack will be popped out first upon an according command - a principle shortly known as "Last in, first out" or LIFO.
Programme Structure and Basic Commands
Every proper Chef programme starts with a recipe title of the programmer's choice, for example "Hello World Soufflé" or "Collatz sequences à la Bolognese". The title has no further influence on the programme.
Variable Declaration
After an optional comment paragraph there has to be a list of ingredients. Ingredients are a chef programme's variables. Depending on whether an ingredient is dry or liquid, it is treated as number or character, the last only being useful for output. Liquid ingredients are also specified by numbers, which are translated into characters via Unicode. The ingredient section is always opened by the line Ingredients. They should be listed in the following way:
[amount] [measure] [ingredient],
where [amount] specifies which value is assigned to the variable called ingredient. The [measure] indicates the ingredient's data type and may be g, kg or pinch(es) for dry; ml, l or dash(es) for liquid or cup(s), tea- or tablespoon(s) for unspecified ingredients. The latter can be combined with the prefixes heaped and level which specify the according ingredients to be dry ones. As you can see, Chef encourages diversity.
Stacks
The stacks Chef operates on are referred to as mixing bowls and baking dishes. The difference between them is that only baking dishes are output in the end, whereas most methods can only be applied to mixing bowls.
Commands
The actual code is opened by the line Method. After that, a number of commands follows, mmostly stack operations. For example, look at the quite simple "Hello world!" programme behind this link.
First, the ingredients are declared. Note that their initials match the Unicode values specified by the amount. This is only for orientation and not mandatory: The important thing are the numbers.
The ingredients, some dry, others liquid, are put into the mixing bowl in reverse order by the "Put... into" command. In this case we need not more than one stack - in this case we would make use of a 1st, 2nd, 3rd... mixing bowl, appearing in the code exactly this way.
Not all ingredients are liquid, as they need to be to be given out as characters. Here comes the "Liquefy" command, which may either be used on a specific ingredient or on the contents of a mixing bowl. Afterwards, the mixing bowl's contents are poured into the baking dish for serving, i.e. output. "Serves 1" means that only the first baking dish's contents are output.
Loops
Loops are rather hard to recognise for Chef beginners. Any verb that is not already used as a method introduces a loop when used on a variable, for example:
Sift the flour.
...[Loop body]...
Rub the flour until sifted.
The first sentence checks whether flour equals zero. If not, the loop's body will be executed. Upon the matching until statement1, flour will be decremented, and the loop restarted. The variable before until does not need to be the same as in the loop's beginning, which allows while- and if-constructions. Set aside matches the break command in languages like C or Python and causes the innermost loop to end immediately.
Further Reading
- David Morgan-Mar's Chef Documentation, including code examples
- A Chef interpreter, written in Perl