Money-native · real, tested code

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.