From 91aa0afcd34cff345f1f7293d82fec7d00082d8b Mon Sep 17 00:00:00 2001 From: eunhhu Date: Fri, 25 Sep 2026 15:05:58 +0100 Subject: Add conditional expressions and table views if c { a } else { b }, with else-if chains, is an expression anywhere a value goes. Only the chosen branch runs, every branch gives the same type, and nesting that would pass Pure's limit of 8 value-carrying joins is a compile error. view name = each row in list { column = value ... } declares a table with a row per item; columns read their row as an index of the list. An index now reads and writes its item's fields directly (at.title, at.done = 1), so 'position' cannot name a record field. examples/tasks.aup gains conditional views and a board table and still matches its reference model; a new check confirms the unchosen branch is never computed. --- examples/tasks.aup | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'examples/tasks.aup') diff --git a/examples/tasks.aup b/examples/tasks.aup index 4c6627f..38d06ef 100644 --- a/examples/tasks.aup +++ b/examples/tasks.aup @@ -27,16 +27,23 @@ on typed { } on up.down { at = at - 1 } on down.down { at = at + 1 } -on toggle.down { tasks[at].done = !tasks[at].done } +on toggle.down { at.done = !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}!" } +on shout.down { tasks[at].title = "{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 +view current = if tasks.count > 0 { at.title } else { "(empty)" } +view status = if tasks.count > 0 { "{at.position + 1}/{tasks.count}" } else { "empty" } +view finished = at.done # no value while the list is empty + +# One row per task. A surface computes only the rows it shows. +view board = each task in tasks { + title = task.title + mark = if task.done { "x" } else { " " } + here = task.position == at.position +} -- cgit v1.2.3