Skip to content

Intermediate variables

In complex recipes, you often create sub-components (like a dough, a sauce, or a filling) that are assembled in later stages. Gram allows you to declare these sub-components as intermediate variables.

Once declared, an intermediate &variable can be referenced, measured, or used as a baseline for relative percentage calculations.

  1. Declaration (->&name) You declare the intermediate variable at the end of a step or in a section header using the ->& arrow operator.

  2. Scoping and graph registration The compiler registers the variable in the global symbol scope, calculates its cumulative produced mass, and sets up dependency links for ALAP scheduling.

  3. Downstream consumption (&name) Subsequent steps reference the variable using &name, optionally specifying an extracted quantity (e.g. &puff pastry{200g}) or computing relative ratios (@salt{2% &dough}).

  4. Automatic shopping list unwrapping The intermediate item is kept on the step ingredient list for cooking guidance, but automatically excluded from the shopping list — only its raw constituent ingredients are purchased.

When placed at the very end of a step paragraph, the variable captures everything produced in that specific step:

[Add] @flour{200g} and @water{100ml}. Mix until combined. ->&dough

[Rest] Let the &dough rest for ~_{1h}.

When placed at the end of a ## Section title, the variable captures the cumulative output of the entire section:

## Puff pastry ->&puff pastry{}

[Mix] @flour{250g}, @water{120ml}, and @salt{5g}.

[Rest] In the #fridge for ~_{1h}.

[Incorporate] @butter{200g} by folding the dough multiple times.

// The &puff pastry variable now represents the final output of the entire section.

To use a previously declared variable, prefix its name with &, with no space in between: an & followed by a space (salt & pepper) stays plain text.

[Line] Use the &puff pastry{} to line the tart tin.

You can also assign a quantity to it for display purposes in the rendered recipe:

[Roll] Take &puff pastry{200g} and roll it out.

When a variable is declared at the section level, it enters the recipe’s global symbol scope. You can declare a variable in the very first section and safely reference it across any subsequent section.

You can calculate an ingredient’s mass as a percentage of an intermediate variable’s total weight (see Relative quantities):

[Mix] The ingredients to form the dough. ->&dough

[Add] @salt{2% &dough}.

The compiler helps you maintain clean and conflict-free code by checking variable usage:

  • SCOPE_CONFLICT: Triggered if the same intermediate variable name is declared multiple times across different sections.
  • UNDEFINED_REFERENCE: Triggered if &name references an intermediate variable that has not been declared yet.
  • CIRCULAR_REFERENCE: Triggered if an intermediate variable depends on itself directly or through another variable.