Chef
Programs are recipes. Ingredients are variables, mixing bowls are stacks, and the dish is served as output.
David Morgan-Mar, 2002 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 3 examples and 3 known programs · Hello World on Try It Online: identical · Test method
Run it
Hello World
Expected output
Hello world!
Output
The idea
David Morgan-Mar designed Chef around 2002. His design goal was that a program should not only produce the right output but also be a recipe you could follow, and ideally enjoy eating. Metric measures are preferred, but cups and spoons are allowed.
Read the story
Like Shakespeare, it hides a stack machine inside a familiar genre. The recipe's headings are syntax, the cooking verbs are instructions, and the units tell the interpreter how to print a value.
Some people have baked Chef programs. A Hello World cake exists, with chocolate sauce as an auxiliary recipe.
The machine
A recipe has a title, an ingredient list, a method, and an optional Serves N. line. More recipes can follow; they are subroutines.
- Ingredients are variables with a starting number:
72 g sugar. Dry measures (g,kg,pinches) make a value print as a number. Liquid measures (ml,l,dashes) make it print as a character. - Mixing bowls are stacks. Baking dishes are stacks that get printed at the end.
| Method line | Does |
|---|---|
Take X from refrigerator. | Read a number into X |
Put X into the mixing bowl. | Push X |
Fold X into the mixing bowl. | Pop into X |
Add / Remove / Combine / Divide X. | Top of bowl +, −, ×, ÷ X |
Liquefy contents of the mixing bowl. | Mark everything in the bowl as characters |
Stir the mixing bowl for N minutes. | Roll the top value down N places |
Mix the mixing bowl well. | Shuffle the bowl at random |
Pour contents of the mixing bowl into the baking dish. | Copy the bowl onto the dish |
Verb the X. … Verb until verbed. | Loop while X is not zero, e.g. Sift the flour. … Sift until sifted. |
Set aside. | Break out of the loop |
Serve with chocolate sauce. | Call the auxiliary recipe; it works on copies of the bowls |
Refrigerate. | Return from a recipe |
Serves N. | Print the first N dishes, each from the top down |
Example
Traced by hand: the bowl gets 105, then 72 on top.
Hi Pudding.
Ingredients.
72 ml milk
105 ml cream
Method.
Put cream into the mixing bowl.
Put milk into the mixing bowl.
Pour contents of the mixing bowl into the baking dish.
Serves 1.
Traced by hand: the bowl gets 105, then 72 on top. Pouring keeps the order. Serves 1 prints the dish from the top down: 72 then 105. Both are liquid (millilitres), so they print as characters: Hi.
Change ml to g and the same recipe prints 72105. The unit is the type.
Checked examples
Example
Expected output
1 2 3 4 5
Output
Example
Expected output
7
Output
Quirks
- Chef-lite implements part of the language, as described above.
- A run stops after 3,000,000 steps.
Try this
- Write a recipe that prints
OK. - Use a loop such as
Beat the eggs.…Beat until beaten.to print the numbers 5 down to 1. (Avoid verbs that are already commands, likeStirorMix.) - Hard: write a recipe that is both a correct program and something you would cook.
Patterns it teaches
- Camouflage: a recipe that runs. The best Chef programs are also edible, which is a much stricter disguise than merely looking like a recipe.
- Stack machines: bowls and dishes are stacks;
Stiris a rotate,Foldis a pop. - Nondeterminism:
Mix wellshuffles a bowl, so the same recipe can print different things.
Further
- esolangs.org/wiki/Chef
- The original specification: dangermouse.net/esoteric/chef.html
- Mike Worth's baked Hello World cake (2013), linked from the esolangs page.
See also
Pseudonatural
Stack-based
Write your own in Run Convert a program from Chef
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: chef.
Command line
shib run chef -e 'Countdown.
Ingredients.
5 g counter
Method.
Repeat the counter.
Put counter into the mixing bowl.
Count the counter until repeated.
Pour contents of the mixing bowl into the baking dish.
Serves 1.
'shib manual chefSource
- Module
langs/grid/index.js- Interpreter
langs/grid/chef.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org