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.
Variable lifecycle
Section titled “Variable lifecycle”-
Declaration (
->&name) You declare the intermediate variable at the end of a step or in a section header using the->&arrow operator. -
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.
-
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}). -
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.
Declaring a variable
Section titled “Declaring a variable”Step-level declaration
Section titled “Step-level declaration”When placed at the very end of a step paragraph, the variable captures everything produced in that specific step:
Section-level declaration
Section titled “Section-level declaration”When placed at the end of a ## Section title, the variable captures the cumulative output of the entire section:
Using a variable
Section titled “Using a variable”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.
You can also assign a quantity to it for display purposes in the rendered recipe:
Advanced mechanics
Section titled “Advanced mechanics”Global scoping
Section titled “Global scoping”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.
Relative quantities
Section titled “Relative quantities”You can calculate an ingredient’s mass as a percentage of an intermediate variable’s total weight (see Relative quantities):
Compiler diagnostics
Section titled “Compiler diagnostics”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&namereferences an intermediate variable that has not been declared yet.CIRCULAR_REFERENCE: Triggered if an intermediate variable depends on itself directly or through another variable.