From c4e49c4679853b489d36f2195f0b1dad97428a6e Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 2 Oct 2022 12:12:19 +1100 Subject: [PATCH] Added an example to the main page --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index d3916e4..ffa210b 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,24 @@ The Toy programming language is a procedural bytecode-intermediate interpreted l The host will provide all of the extensions needed on a case-by-case basis. Script files have the `.toy` file extension, while binary files have the `.tb` file extension. +``` +fn makeCounter() { //declare a function like this + var total: int = 0; //declare a variable with a type like this + + fn counter(): int { //declare a return type like this + return ++total; + } + + return counter; //closures are explicitly supported +} + +var tally = makeCounter(); + +print tally(); //1 +print tally(); //2 +print tally(); //3 +``` + # Nifty Features * Simple C-like syntax