From 399faa1f97390215628d245f006610a9586ff1e9 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 17 Apr 2017 13:56:14 +0200 Subject: Add some example programs --- example/countup.slang | 9 +++++++++ example/fizzbuzz.slang | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 example/countup.slang create mode 100644 example/fizzbuzz.slang 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 -- cgit v1.2.3