From e90d494d718762d402871c9194ab036088dd9e0c Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sat, 26 Sep 2026 16:38:33 +0100 Subject: Add keyed lists and text comparison state xs: list of R by field keeps its items in that field's order, each key once: xs.add(R { ... }) places an item (a taken key fails the event with exists), xs[key] finds one by halving (its field, or its index), xs.has(key) asks, xs.remove(key) removes. append and insert are refused on a keyed list, add on another, and a key field is never assigned. Texts compare with == != < <= > >= by their bytes. Checked against a Python model over 3,600 random steps with a text-keyed and a number-keyed list; 13 diagnostics; examples/tally.aup. --- examples/tally.aup | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/tally.aup (limited to 'examples/tally.aup') diff --git a/examples/tally.aup b/examples/tally.aup new file mode 100644 index 0000000..cdff8dd --- /dev/null +++ b/examples/tally.aup @@ -0,0 +1,32 @@ +# Typed words, tallied. A list keyed by the word keeps each word once, in +# order; tallies[word] finds it by halving, whatever the list's length. +record Tally { + word: text + times = 0 +} +state tallies: list of Tally by word +state at: index of tallies +input typed = text +input forget = key Delete +input up = key ArrowUp +input down = key ArrowDown + +on typed { + if !tallies.has(typed) { + tallies.add(Tally { word: typed }) + } + tallies[typed].times = tallies[typed].times + 1 + at = tallies[typed] +} +on forget.down { tallies.remove(at) } +on up.down { at = at - 1 } +on down.down { at = at + 1 } + +view current = if tallies.count > 0 { "{at.word}: {at.times}" } else { "-" } +view words = tallies.count +view typed_total = sum(t.times for t in tallies) +view most = max(t.times for t in tallies) +view table = each t in tallies { + word = t.word + times = t.times +} -- cgit v1.2.3