aboutsummaryrefslogtreecommitdiffstats
path: root/examples/words.aup
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-25 15:14:08 +0100
committereunhhu <[email protected]>2026-09-25 15:14:08 +0100
commitc298c2eec0b7ec0fcdacb8f661a9da3c184d2960 (patch)
treeaffe490db2b070f0b064bbb9bf5ade49d45a9293 /examples/words.aup
parent91aa0afcd34cff345f1f7293d82fec7d00082d8b (diff)
downloadaup-c298c2eec0b7ec0fcdacb8f661a9da3c184d2960.tar.gz
aup-c298c2eec0b7ec0fcdacb8f661a9da3c184d2960.zip
Add fns and libraries
fn name(params) = value declares one expression, inlined where it is called: arguments are computed once onto the stack and the body reads them with PICK, so a fn costs no runtime call and keeps Pure's bound on work. Parameters take any kind of value; recursion is a compile error. use name reads name.aup beside the source or from AUP_PATH. A library declares only fns and uses, sees only its parameters, and is called as name.fn(...). Diagnostics now carry the file they are in, and the compiler takes a loader so that sources come from the host. examples/words.aup is such a library; examples/tasks.aup uses it and still matches its reference model.
Diffstat (limited to 'examples/words.aup')
-rw-r--r--examples/words.aup5
1 files changed, 5 insertions, 0 deletions
diff --git a/examples/words.aup b/examples/words.aup
new file mode 100644
index 0000000..2bfc0a5
--- /dev/null
+++ b/examples/words.aup
@@ -0,0 +1,5 @@
+# Words for counts and marks. A library: only fns, no state, so any app can
+# `use words` and call words.counted(...).
+fn plural(count, one, many) = if count == 1 { one } else { many }
+fn counted(count, one, many) = "{count} {plural(count, one, many)}"
+fn check(done) = if done { "x" } else { " " }