Keep a Double-Entry Ledger in Larzscript
Post debits and credits that always balance - the accounting equation holds after every single posting, not just at the end.
ledger.post() takes a debit account, a credit account, and an amount in one call, so there's no way to record half a transaction; ledger.is_balanced() and trial_balance() prove the books reconcile.
larzscript pkg install ledger
Code
import "ledger" as ledger let books = ledger.new() ledger.post(books, "cash", "revenue", 10000, "sale #1") ledger.post(books, "expenses", "cash", 2000, "rent") print(ledger.balance(books, "cash")) print(ledger.is_balanced(books)) print(ledger.trial_balance(books))
Output
8000
true
{cash: 8000, expenses: 2000, revenue: -10000}Why this matters in Larzscript
Double-entry bookkeeping is the kind of invariant a money-native language's ecosystem can enforce structurally - post() simply has no signature that lets one side of a transaction go missing.
Related
larzledgerDouble-entry bookkeeping - every posting balances by construction→Split a Bill Fairly in LarzscriptDivide a bill among people so it reconciles exactly to the cent - no language other than Larzscript treats this as a stack primitive rather than app-level logic.→Hold Funds in Escrow in LarzscriptHold a payer's funds, then release them to a payee or refund them back - using the language's own wallet and pay keywords, not a bolted-on library.→Rate-Limit API Requests in LarzscriptToken-bucket rate limiting in about 20 lines - cap a caller to N requests with a steady refill rate instead of a blunt fixed window.→