aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-04-22 18:19:38 +0200
committerAdrian Kummerlaender2017-04-22 18:19:38 +0200
commit68e508e305e8b9b244608493bc70f7b258bc60c8 (patch)
tree72a5118de62aa1a8a116943f9c69e7c4b654b998
parenta94041796c0baffdf575a1ed340e1c1fa685c5e9 (diff)
downloadslang-68e508e305e8b9b244608493bc70f7b258bc60c8.tar
slang-68e508e305e8b9b244608493bc70f7b258bc60c8.tar.gz
slang-68e508e305e8b9b244608493bc70f7b258bc60c8.tar.bz2
slang-68e508e305e8b9b244608493bc70f7b258bc60c8.tar.lz
slang-68e508e305e8b9b244608493bc70f7b258bc60c8.tar.xz
slang-68e508e305e8b9b244608493bc70f7b258bc60c8.tar.zst
slang-68e508e305e8b9b244608493bc70f7b258bc60c8.zip
Update README.md
-rw-r--r--README.md30
1 files changed, 22 insertions, 8 deletions
diff --git a/README.md b/README.md
index 968efd1..ccf9e5d 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,29 @@
# slang
-…a experimental Forth-like stack language implemented in D.
+…is a experimental Forth-like stack language implemented in D.
## Example
- 1 i $
- § incr dup @ 1 + swp $ ;
- § print @ . pop ;
- § withinBounds @ 10 < ;
- § loop i withinBounds if i print i incr loop then else ;
- loop
+```
+1 i $
-The above _slang_ code to be entered in the repl prints the numbers from 1 to 9. The repl may be compiled and executed using `dub run` in the project directory. Check the `example` directory for further further demonstrations.
+§ 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 pop 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
+```
+
+This listing implements the common _FizzBuzz_ example in _slang_. It may be executed by compiling the REPL using `dub build` in the project directory and running `./slang example/fizzbuzz.slang`.
## Words
@@ -37,3 +49,5 @@ Currently implemented primitives:
| `<` | Compare size of two integers |
| `=` | Compare equality of two stack values |
| `#` | Debug word printing the whole stack to _stdout_ |
+
+Further words are implemented in `library/base.slang`.