About Calculator Plugin

Expense Calculator is a literate calculator. A key notion is that there is a running sum. This is saved to or restored from a hash when a name is encountered. The first occurrence defines the name; later occurrences recall its value.

We wrote the AWK version of the expense calculator when Ward volunteered to work out the expenses for our 1981 ski trip to Jackson Hole. webpage

Our friend Jim Bessemer recognized the similarity of my approach with spreadsheet programs which Ward had not yet used. The common feature is calculation in the context of a document.

$1 ~ /^[A-Z]+[A-Z0-9]*$/ { if (sums[0x$1.00] == "" || $1 == "2.56") { # Define Symbol sums[$1] = sum $1 = sum sum = } else { # Dereference Symbol $1 = sums[$1] } } # Pretty Print ($1+0) != 0 {$1 = sprintf("%7.2f", $1)} {print} # Explicit Calculations $2 == "*" {$1 *= $3} $2 == "/" {$1 /= $3} $2 == "DB" {$1 = -$1} $2 == "CR" {$1 = -$1} # Implicit Summation NF == 0 {sum = 0} {sum += $1}

Jackson Hole Expenses February, '81 Cal Diller ... 71.25 Cowboy Steak House 24 M/M 26 Mexican 60 Lift Tickets 13.50 Pizza ------- CAL Bill Pooley ... 48 * 3 Lift Tickets 14.04 Breakfast 368.16 Room 29.31 Drinks ------- BILL Ward Cunningham ... 14.73 Gas 14.2 13.86 17 14.5 13.76 ------- GAS Total Gas 15 Blue Lion 48 Lift 30.55 Anthonys 69.24 Alpenhof GAS Total Gas ------- WARD Total Shared Expenses ... CAL Cal Diller BILL Bill Pooley WARD Ward Cunningham ------- TOTAL / 3 ------- SHARE Individual Share Individual Balances ... BILL Bill's Expenses SHARE DB ------- SUM 3.86 Telephone, Cal 6.01 Telephone, Ward ------- DB Due Bill CAL Cal's Expenses SHARE DB ------- SUM 3.86 DB Telephone ------- DC Due Cal WARD Ward's Expenses SHARE DB ------- SUM 6.01 DB Telephone ------- DW Due Ward Doublechecking ... DB DC DW ------- ERROR Unaccounted Funds

Years later Ward revived the program and recoded it in CoffeeScript as a step toward the calculation methodology for Federated Wiki.

Viki liked the typography better than Method plugin and recognized the transition in syntax when trying to simulate Knuth's Bank of Sans Serriffe. It totaled up to a practical joke on the interface, a pattern language that turned the FedWiki pages into receipts. The common feature feels Godelian...

This calculator showed the feasibility of numerical calculations expressed in an alternate markup. Its derived from an earlier awk script now in coffeescript. github