OtterCalcOtterCalc

Totals & references

Sum blocks with subtotal and total, reference any line with R2.

A line that just says subtotal adds up the run of values directly above it. Blank lines and headings end a block, so each section of your document can have its own subtotal.

groceries = 320
transport = 150
fun = 90
subtotal
320
150
90
560

total

total sums every value line above it in the whole document, and it never double-counts other totals or subtotals. Both keywords work inside an assignment, and both keep units, so a block of dollars sums to dollars.

q1 = $38k
q2 = $41k
spend = total
$38,000.00
$41,000.00
$79,000.00

average, count, and inline stats

average and count work like subtotal on the block above: average keeps the unit, count just counts the value lines. Aggregates written one under the other share the same block, so total, then average, then count all describe the values above them. For a one-liner, write average of or median of with a list, and there is also midpoint of A and B, range of a list (max minus min), and min/max/std of a list.

10
20
30
average
median of 10, 20 and 30
midpoint of 40 and 90
range of 3, 9, 4
10
20
30
20
20
65
6

The block rules, exactly

A subtotal block is broken by blank lines, text lines, and other totals or charts, so each section sums just its own run of values. Lines with errors, dates, or rate declarations are skipped but do not break the block, so one typo in a long budget does not zero your sum. Mixed lines follow one rule: summing upward from the total, plain numbers adopt the unit (2500, 800, $680 totals $3,980), compatible units and currencies convert, and the first line that does not fit ends the run instead of erroring. An empty block sums to 0.

groceries = 40
transport = 15
subtotal
 
concert = 60
subtotal
40
15
55
60
60

Row references

R2 means the result of line 2, the number shown in the left gutter. The fastest way to write one is to click any result pill. References only point upward, and units come along, so a reference to a distance stays a distance.

12 km
8 km
R1 + R2
12 km
8 km
20 km

prev, the line just above

prev is shorthand for the result of the nearest value line above, so you can keep a running calculation going without naming each step. It skips headings, blank lines, dates and charts to find the last real number, and units and currencies come along. Spanish is anterior, French is précédent.

dinner = 45
with tip = prev + 18%
per person = prev / 4
45
53.1
13.275

References repair themselves

If you insert or delete lines above a reference, the reference renumbers automatically so it keeps pointing at the same content. The reference you are actively typing is never touched. And if you name a variable r2, your variable wins over the reference syntax.