aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/countup.slang9
-rw-r--r--example/fizzbuzz.slang16
2 files changed, 25 insertions, 0 deletions
diff --git a/example/countup.slang b/example/countup.slang
new file mode 100644
index 0000000..69e71db
--- /dev/null
+++ b/example/countup.slang
@@ -0,0 +1,9 @@
+1 i $
+
+§ incr dup @ 1 + swp $ ;
+§ print @ . pop ;
+§ withinBounds @ 10 < ;
+
+§ loop i withinBounds if i print i incr loop then else ;
+
+loop
diff --git a/example/fizzbuzz.slang b/example/fizzbuzz.slang
new file mode 100644
index 0000000..653c180
--- /dev/null
+++ b/example/fizzbuzz.slang
@@ -0,0 +1,16 @@
+1 i $
+
+§ incr dup @ 1 + swp $ ;
+§ withinBounds @ 100 < ;
+
+§ fizz? @ 3 % 0 = ;
+§ buzz? @ 5 % 0 = ;
+
+§ fizzbuzz_or_fizz buzz? if fizzbuzz then fizz else . pop ;
+§ buzz_or_print dup buzz? if buzz then @ else . pop ;
+
+§ branch dup fizz? if fizzbuzz_or_fizz then buzz_or_print else ;
+
+§ loop i withinBounds if i branch i incr loop then else ;
+
+loop