From f9eaf1a65794415aba2b456b08f922ddacbcf2f5 Mon Sep 17 00:00:00 2001 From: funkywaddle Date: Mon, 24 Nov 2025 06:07:09 +0000 Subject: [PATCH] Update README.md. Add array foreach example. Add better formatting. Signed-off-by: funkywaddle --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2864bb9..6662b89 100644 --- a/README.md +++ b/README.md @@ -22,47 +22,61 @@ Waddle is a modern, expressive programming language designed to be intuitive, re ## Basic Syntax ### Type Declaration + +#### Basic type definition ```waddle -// Basic type definition Animal { // Type implementation } - -// Inheritance +``` +#### Inheritance +```waddle Animal/Dog { // Dog-specific implementations } +``` -// Interface definition +#### Interface definition +```waddle @Mammal { // Interface methods } +``` -// Interface implementation +#### Interface implementation +```waddle Animal/Dog -> [Mammal, Domesticated] { // Multiple interface support } ``` ### Functions + +#### Function declaration + +##### Public function ```waddle -// Function declaration -// Public function +fn calculateArea(width: Integer, height: Integer) -> [Decimal] { rtn width.multiply(height); } +``` -// Protected Function +##### Protected Function +```waddle fn calculateArea(width: Integer, height: Integer) -> [Decimal] { rtn width.multiply(height); } +``` -// Private Function +##### Private Function +```waddle -fn calculateArea(width: Integer, height: Integer) -> [Decimal] { rtn width.multiply(height); } +``` -// Lambda expression +##### Lambda expression +```waddle areaCalculator = fn(width: Integer, height: Integer) -> [Decimal] { rtn width.multiply(height); } @@ -90,26 +104,46 @@ result = riskyOperation().attempt { ``` ### Iteration + +#### Forward iteration ```waddle -// Forward iteration loop(i, 0->10) { my.output.print(i); } +``` -// Foward iteration, with step +#### Foward iteration, with step +```waddle loop(i, 0->10, 2) { my.output.print(i); // outputs 0, 2, 4, 6, 8, 10 } +``` -// Reverse iteration +#### Reverse iteration +```waddle rloop(i, 10->0) { my.output.print(i); } +``` -// Reverse iteration, with step +#### Reverse iteration, with step +```waddle rloop(i, 10->0, 2) { my.output.print(i); // outputs 10, 8, 6, 4, 2, 0 } +``` + +#### Foreach loop on arrays +```waddle +Integer<> nums.set(<1, 2, 3, 4>); + +nums.each( + i -> { + if(i.mod(2).eq(0)){ + my.output.print(i); // outputs 2, 4 + } + } +); ```