aboutsummaryrefslogtreecommitdiff
path: root/examples/guard.fwd
diff options
context:
space:
mode:
Diffstat (limited to 'examples/guard.fwd')
-rw-r--r--examples/guard.fwd33
1 files changed, 33 insertions, 0 deletions
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);
+}