From d6188ed911a9d6c00ac498135db3b5bca8a8859a Mon Sep 17 00:00:00 2001 From: Bobbi Webber-Manners Date: Tue, 1 May 2018 11:49:44 -0400 Subject: [PATCH] Pasted example code. --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index c5b9caf..bfa0e5a 100644 --- a/README.md +++ b/README.md @@ -575,4 +575,27 @@ Then you can run the VM program for your platform. It will load the bytecode fr ## VM Internals +# Code Examples + +## Recursive Factorial + +This example shows how EightBall can support recursion. I should point out that it is much better to do this kind of thing using iteration, but this is a fun simple example: + + pr.dec fact(3); pr.nl + end + + sub fact(word val) + pr.msg "fact("; pr.dec val; pr.msg ")"; pr.nl + if val == 0 + return 1 + else + return val * fact(val-1) + endif + endsub + +`fact(3)` calls `fact(2)`, which calls `fact(1)`, then finally `fact(0)`. + See `eightballvm.h` for technical details. + +## Prime Number Sieve +