aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-25 13:34:43 +0100
committereunhhu <[email protected]>2026-09-25 13:34:43 +0100
commita459632cbb93b46c013556465a9e69b0baad745a (patch)
tree05ef189a3eebb7c954a348f6501403d9d60cabf9 /examples
parentb4ec5eeaab82ee7c876f7d02e6430997f7240899 (diff)
downloadaup-a459632cbb93b46c013556465a9e69b0baad745a.tar.gz
aup-a459632cbb93b46c013556465a9e69b0baad745a.zip
Add records, lists and indices
A record declares named number and text fields with defaults. A list of a record is runtime-owned state, and an index of a list always names one of its items: it follows its item across inserts and removes and stops at the ends. Items are read and changed by field (tasks[at].title), appended or inserted as record values whose missing fields take defaults, and removed by index. Using an index of another list is a compile error. examples/tasks.aup matches a Python reference model over 4,800 random steps, including events that fail on an empty list. Replacing it with a module whose record gained and reordered fields keeps every item.
Diffstat (limited to 'examples')
-rw-r--r--examples/tasks.aup42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/tasks.aup b/examples/tasks.aup
new file mode 100644
index 0000000..4c6627f
--- /dev/null
+++ b/examples/tasks.aup
@@ -0,0 +1,42 @@
+# A task list. The runtime owns the list: the index always names an item,
+# stays on it when items are inserted or removed before it, stops at the
+# ends, and a failed event leaves the list as it was.
+record Task {
+ title: text
+ done = 0
+}
+
+state tasks: list of Task
+state at: index of tasks
+state made = 0
+
+input typed = text
+input up = key ArrowUp
+input down = key ArrowDown
+input toggle = key Space
+input drop = key Delete
+input top = key Home
+input bottom = key End
+input again = key KeyD
+input shout = key KeyS
+
+on typed {
+ tasks.append(Task { title: typed })
+ at = tasks.last
+ made = made + 1
+}
+on up.down { at = at - 1 }
+on down.down { at = at + 1 }
+on toggle.down { tasks[at].done = !tasks[at].done }
+on drop.down { tasks.remove(at) }
+on top.down { at = tasks.first }
+on bottom.down { at = tasks.last }
+# A copy goes before the current task, which stays current.
+on again.down { tasks.insert(at, Task { title: tasks[at].title, done: tasks[at].done }) }
+on shout.down { tasks[at].title = "{tasks[at].title}!" }
+
+view count = tasks.count
+view position = at.position
+view current = tasks[at].title
+view status = "{at.position + 1}/{tasks.count}"
+view finished = tasks[at].done