The Cheffers Cookbook

Course seven

Call In the Sous-Chef

On the menu: auxiliary recipes β€” Chef's functions β€” and your graduation dish.

New kitchen skills

Auxiliary recipes Β· Serve with … Β· the first-bowl handoff Β· Refrigerate Β· the plating pattern.

No chef cooks alone

Once recipes get ambitious, you want helpers: a sauce recipe you can call whenever a dish needs sauce. Programmers call these functions. Chef calls them auxiliary recipes β€” complete little recipes (title, ingredients, method) written below the main one, made on demand by a sous-chef. You call one with a single sentence in your method:

Serve with secret sauce.

The head chef pauses, the sous-chef cooks, the head chef continues. Three house rules govern the handoff:

  1. The sous-chef works on photocopies. They start with an exact copy of all your mixing bowls and baking dishes. Whatever they smash, spill or shuffle at their own station never touches yours.
  2. They can't see your pantry. An auxiliary recipe has its own ingredient list; your ingredient names mean nothing to it. The only things it receives are the values sitting in the copied bowls.
  3. They hand back one bowl. When the sous-chef finishes, the contents of their first mixing bowl are poured on top of your first mixing bowl. That's the entire delivery: whatever they want you to have, they leave in bowl one.

One more staff instruction: Refrigerate. ends a recipe on the spot β€” in an auxiliary recipe it means β€œdone early, hand back my first bowl now.” (The variant Refrigerate for 2 hours. also prints the first 2 baking dishes before stopping β€” an early Serves with a dramatic exit.)

Tonight's recipe: Squared Milkshake

A milkshake so rich it multiplies. The head chef takes a number from the refrigerator and puts it in the bowl; the sous-chef squares whatever's on top; the head chef plates it. Watch how little the main method knows about how the sauce is made β€” that's the whole point of functions.

Squared Milkshake Β· recipe Open in playground β–Ά
Squared Milkshake.

Takes any number from the refrigerator and serves it multiplied by itself. The head chef does none of the real work: a sous-chef prepares the secret sauce.

Ingredients.
radishes

Method.
Take radishes from refrigerator. Put radishes into the mixing bowl. Serve with secret sauce. Fold radishes into the mixing bowl. Clean the mixing bowl. Put radishes into the mixing bowl. Pour contents of the mixing bowl into the baking dish.

Serves 1.

Secret Sauce.

Ingredients.
essence

Method.
Fold essence into the mixing bowl. Clean the mixing bowl. Put essence into the mixing bowl. Combine essence into the mixing bowl.
Input panel
7
Output
49

Shift report, station by station

With input 7:

StationActionBowls
Head chefTake, Putmain bowl: [7]
β€” call β€”Serve with secret sauce.sous-chef's copy: [7]
Sous-chefFold essence β€” scoops the 7 into essencecopy: [ ]
Sous-chefClean, Put essence, Combine essence β€” 7 Γ— 7copy: [49]
β€” handoff β€”sous-chef's bowl one lands on top of the head chef'smain bowl: [7, 49]
Head chefFold radishes, Clean, Put radishesmain bowl: [49]
Head chefPour, Serves 1.prints 49
The plating pattern

Spot the three-step both chefs used: Fold the value you care about out of the bowl, Clean away the leftovers, Put the value back. It's how a Chef program says β€œkeep only the result.” Without it, the head chef's bowl still holds the original 7 under the 49, and dinner would print as 497 β€” the handoff stacks onto your bowl, it doesn't replace it.

And because auxiliary recipes are full recipes, they can call other auxiliary recipes β€” including themselves. That's recursion, and it's exactly how the most famous Chef program, Fibonacci Numbers with Caramel Sauce, gets an awful lot of caramel made. (Cheffers lets sous-chefs stack 64 deep before it declares the kitchen overstaffed.)

Your graduation dish πŸŽ“

You've now tasted the entire language β€” every course from Put to Serve with. To prove it, here is a dish written with everything you know: it approximates the golden ratio Ο† β‰ˆ 1.618 using Fibonacci numbers and integer-only math, then fakes the decimal point by melting a 46 g ingredient (46 is the character code for β€œ.”). Read it slowly β€” you can now decode every single sentence:

Golden Ratio Biscotti Β· graduation dish Open in playground β–Ά
Golden Ratio Biscotti.

Approximates the golden ratio as "1.6180" using Fibonacci and fixed-point math (times 10,000). Integer-only; no external input.

Ingredients.
0 g almonds
1 g butter
25 g eggs
10000 g flour
0 g honey
0 g chocolate
0 g sprinkles
0 g vanilla
46 g chocolate chips

Method.
Beat the eggs.
Clean the mixing bowl.
Put almonds into the mixing bowl.
Add butter to the mixing bowl.
Fold honey into the mixing bowl.
Put butter into the mixing bowl.
Fold almonds into the mixing bowl.
Put honey into the mixing bowl.
Fold butter into the mixing bowl.
Beat the eggs until beaten.
Clean the mixing bowl.
Put butter into the mixing bowl.
Combine flour into the mixing bowl.
Divide almonds into the mixing bowl.
Fold chocolate into the mixing bowl.
Put chocolate into the mixing bowl.
Divide flour into the mixing bowl.
Fold sprinkles into the mixing bowl.
Put sprinkles into the mixing bowl.
Combine flour into the mixing bowl.
Fold honey into the mixing bowl.
Put chocolate into the mixing bowl.
Remove honey from the mixing bowl.
Fold vanilla into the mixing bowl.
Liquefy chocolate chips.
Clean the mixing bowl.
Put vanilla into the mixing bowl.
Put chocolate chips into the mixing bowl.
Put sprinkles into the mixing bowl.
Pour contents of the mixing bowl into the baking dish.

Serves 1.
Output
1.6180
Try it
  • In Squared Milkshake, remove the head chef's Fold/Clean/Put and confirm you get 497. Then put the plating pattern back.
  • Promote the sous-chef: change Secret Sauce to cube the number instead (one extra Combine).
  • Write a second auxiliary recipe β€” β€œwhipped cream” that doubles β€” and serve the milkshake with both sauces in a row. Predict the result for input 3 before running it. (Squared then doubled β‰  doubled then squared!)
  • Decode the Biscotti's opening loop: which classic recipe from course five's family is Beat the eggs. … Beat the eggs until beaten. hiding? Follow almonds and butter for two laps with a pencil β€” you'll find an old friend from the fixtures: Fibonacci.

Compliments to the chef β€” that's the whole menu. Keep the Pantry Reference stuck to your fridge door, raid the playground's example recipes, and when you're ready for the source of all this delicious chaos, read the original Chef specification β€” it's short, funny, and you now speak its language fluently.