Hacker News new | ask | show | jobs
by liammonahan 2244 days ago
My absolute favorite example of what's possible with awk is this[0] calculator from Ward Cunningham about splitting expenses on a ski trip. It's a really beautiful little piece of code well-adapted to this problem.

[0] - https://c2.com/doc/expense/

4 comments

This is the sort of thing us industry professionals need to study in more depth. It doesn't have the most flexible interface, but it's human-readable, and the implementation is simple, fast, and about as obviously correct as possible.
I glanced through the input and output. When I got to the code, I was startled by how short it was. This page is worthy of its own post on Hacker News. I am now convinced that Ward Cunningham is a genius. I was already pretty sure after reading how he invented the wiki.
I am trying to parse the program based on the article above and comments on the link you posted.

> The first occurrence of a variable name defines it as that sum. Subsequent occurrences become the stored value.

With this quote in mind - why is second `SUM` reference replaced with `-138.95` and not `221.81` (stored value) ?

EDIT: Never mind, now I see it's an exception on line 3.

This reminds me of a story of a guy who wrote a whole company internal debit system like this (coffee, meals out, etc) and it turned into a currency. I feel like I either saw it here, or a similar forum. Anyone have a link? My searches have not found it...
That's it! You found it! Thank you.