Appearance
Variables
A rule does not declare anything. When it is evaluated, a fixed set of variables is already in scope, describing the step being judged. You write comparisons against those names directly.
The six base variables
| Variable | Type | Description |
|---|---|---|
prev_sum | number | The running total accumulated from all previous steps, before the current candidate is applied. |
current_value | number | The value the player is trying to play right now. |
current_sum | number | The total that would result if current_value is accepted. Equal to prev_sum + current_value. |
step_index | number | The zero-based position of the current step. 0 is the first step. |
last_step_index | number | The index of the final step (total steps minus one). |
isLastStep | boolean | true when step_index = last_step_index, false otherwise. |
Prefer current_sum
Use current_sum instead of writing prev_sum + current_value — they are identical, but current_sum is easier to read.
The step, before and after
The three sum-and-value variables describe one step from three angles, and picking the right one is most of what makes a rule readable:
prev_sum >= 0 -- the state the abacus was in before this step
current_value < 0 -- the operation being performed
current_sum <= 99 -- the state the abacus would be in afterwardsA rule about what the player may do uses current_value. A rule about where the exercise may go uses current_sum. A rule about what the position must already look like uses prev_sum.
Position within the exercise
step_index, last_step_index, and isLastStep locate the step in the sequence. They are almost always used as an IF guard rather than as the rule itself:
IF step_index = 0 THEN current_value > 0 -- constrains only the opening step
IF isLastStep THEN current_sum = 100 -- constrains only the landingisLastStep is a boolean, so it stands alone as a condition — write IF isLastStep THEN …, not isLastStep = true.
The three derived variables
Three more variables — place, formula, and digitBefore — are derived from current_value and prev_sum for you. They describe which decimal place the candidate affects: place is the place itself (1, 10, 100, …), formula is the normalized 1–9 digit of the operation, and digitBefore is the digit of the running total at that same place before the step is applied. They are what most real rules are built from, and all three are null whenever current_value touches more than one decimal place.
Decimal places covers them in full, including the null behaviour that surprises most authors. That page is worth reading before you write your first real rule.
See also
- Operators — what you can do with these variables.
- Digit functions — inspecting the digits of any of them.
- Context variables — exact semantics, for when you need to be certain.