Update README.md. Add array foreach example. Add better formatting.
Signed-off-by: funkywaddle <paul@funkywaddle.com>
This commit is contained in:
parent
2a74e5d5b6
commit
f9eaf1a657
62
README.md
62
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
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue