From 0cef986e6958a0a6a7e94e8256b0039709aed56b Mon Sep 17 00:00:00 2001
From: Kimplul <kimi.h.kuparinen@gmail.com>
Date: Fri, 6 Dec 2024 20:00:42 +0200
Subject: add trailing closures

+ Useful for guard statements, not entirely sure about the final syntax
  but at least they're possible
---
 examples/guard.fwd | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 examples/guard.fwd

(limited to 'examples/guard.fwd')

diff --git a/examples/guard.fwd b/examples/guard.fwd
new file mode 100644
index 0000000..6af570d
--- /dev/null
+++ b/examples/guard.fwd
@@ -0,0 +1,33 @@
+/* 'any' doesn't actually exist but at the moment I'm not checking types so as
+ * long as there's some type identifier here the compiler will not complain,
+ * will eventually have to fix */
+fwd_println(any a);
+
+guard(bool cond, () err, () ok)
+{
+	if cond {
+		err();
+	} else {
+		ok();
+	}
+}
+
+try_print_one(int a)
+{
+	guard(a < 1) => {
+		fwd_println("smaller than 1");
+	} => ;
+
+	guard(a > 1) => {
+		fwd_println("larger than 1");
+	} => ;
+
+	fwd_println(a);
+}
+
+main()
+{
+	try_print_one(0);
+	try_print_one(1);
+	try_print_one(2);
+}
-- 
cgit v1.2.3