feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune

ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v),
q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding
facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)).

ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no
longer uses, nor anything it calls, and the argument that fills it - including an argument for a
parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is
told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would
make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-26 04:19:56 +03:00
parent 8cf4b3fed6
commit 71735b10a2
151 changed files with 58668 additions and 54719 deletions

View file

@ -5,56 +5,56 @@ import "ludic.base"
program WalletTest {
numbers float
function changes(base_st: mut BaseState, wallet_st: mut WalletState) -> []MoneyChanged { return q_drain(base_st, wallet_changes(base_st, wallet_st)) }
function waiting(base_st: mut BaseState, wallet_st: mut WalletState) -> int { return q_len(wallet_changes(base_st, wallet_st)) }
function changes(wallet_st: mut WalletState) -> []MoneyChanged { return q_drain(wallet_changes(wallet_st)) }
function waiting(wallet_st: mut WalletState) -> int { return q_len(wallet_changes(wallet_st)) }
test "earning and spending move the purse, and each says so" (base_st: mut BaseState, wallet_st: mut WalletState) {
wallet_reset(base_st, wallet_st)
wallet_earn(base_st, wallet_st, 40)
expect(wallet_spend(base_st, wallet_st, 15))
test "earning and spending move the purse, and each says so" (wallet_st: mut WalletState) {
wallet_reset(wallet_st)
wallet_earn(wallet_st, 40)
expect(wallet_spend(wallet_st, 15))
expect_eq(wallet_money(wallet_st), 25)
let cs = changes(base_st, wallet_st)
let cs = changes(wallet_st)
expect_eq(len(cs), 2)
expect_eq(cs[0].after, 40)
expect_eq(cs[1].before, 40)
expect_eq(cs[1].after, 25)
}
test "a spend past what is there is refused and changes nothing" (base_st: mut BaseState, wallet_st: mut WalletState) {
wallet_reset(base_st, wallet_st)
wallet_set(base_st, wallet_st, 10)
changes(base_st, wallet_st)
expect(not wallet_spend(base_st, wallet_st, 11))
test "a spend past what is there is refused and changes nothing" (wallet_st: mut WalletState) {
wallet_reset(wallet_st)
wallet_set(wallet_st, 10)
changes(wallet_st)
expect(not wallet_spend(wallet_st, 11))
expect_eq(wallet_money(wallet_st), 10)
expect_eq(waiting(base_st, wallet_st), 0)
expect_eq(waiting(wallet_st), 0)
expect(wallet_can(wallet_st, 10))
expect(not wallet_can(wallet_st, 11))
}
test "a loss happens anyway, but never below zero" (base_st: mut BaseState, wallet_st: mut WalletState) {
wallet_reset(base_st, wallet_st)
wallet_set(base_st, wallet_st, 7)
wallet_lose(base_st, wallet_st, 20)
test "a loss happens anyway, but never below zero" (wallet_st: mut WalletState) {
wallet_reset(wallet_st)
wallet_set(wallet_st, 7)
wallet_lose(wallet_st, 20)
expect_eq(wallet_money(wallet_st), 0)
}
test "setting what is already there is no change" (base_st: mut BaseState, wallet_st: mut WalletState) {
wallet_reset(base_st, wallet_st)
wallet_set(base_st, wallet_st, 5)
changes(base_st, wallet_st)
wallet_set(base_st, wallet_st, 5)
expect_eq(waiting(base_st, wallet_st), 0)
test "setting what is already there is no change" (wallet_st: mut WalletState) {
wallet_reset(wallet_st)
wallet_set(wallet_st, 5)
changes(wallet_st)
wallet_set(wallet_st, 5)
expect_eq(waiting(wallet_st), 0)
}
test "a save section reads back the same purse" (base_st: mut BaseState, wallet_st: mut WalletState) {
wallet_reset(base_st, wallet_st)
wallet_set(base_st, wallet_st, 123)
test "a save section reads back the same purse" (wallet_st: mut WalletState) {
wallet_reset(wallet_st)
wallet_set(wallet_st, 123)
let root = save_tree()
save_section(root, "wallet", 1, wallet_save(wallet_st))
let text = save_encode(root)
wallet_reset(base_st, wallet_st)
wallet_reset(wallet_st)
let n = load_section(save_decode(text), "wallet")
wallet_load(base_st, wallet_st, n.data, n.version)
wallet_load(wallet_st, n.data, n.version)
expect_eq(wallet_money(wallet_st), 123)
}
}