Update README.md file

This commit is contained in:
Funky Waddle 2025-11-24 22:31:34 -06:00
parent e72d8835f8
commit fbe3d1ef84

View file

@ -54,35 +54,57 @@ Animal/Dog -> [Mammal, Domesticated] {
#### Function declaration #### Function declaration
##### Public function ##### Public function (+fn)
```waddle ```waddle
+fn calculateArea(width: Integer, height: Integer) -> [Decimal] { +fn calculateArea(Integer width, Integer height) -> [Integer] {
rtn width.multiply(height); rtn width.multiply(height);
} }
``` ```
##### Protected Function ##### Protected Function (fn)
```waddle ```waddle
fn calculateArea(width: Integer, height: Integer) -> [Decimal] { fn calculateArea(Integer width, Integer height) -> [Integer] {
rtn width.multiply(height); rtn width.multiply(height);
} }
``` ```
##### Private Function ##### Private Function (-fn)
```waddle ```waddle
-fn calculateArea(width: Integer, height: Integer) -> [Decimal] { -fn calculateArea(Integer width, Integer height) -> [Integer] {
rtn width.multiply(height);
}
```
#### Default Values
```waddle
fn calculateArea(Integer width.default(0), Integer height.default(0)) -> [Integer] {
rtn width.multiply(height); rtn width.multiply(height);
} }
``` ```
##### Lambda expression ##### Lambda expression
```waddle ```waddle
areaCalculator = fn(width: Integer, height: Integer) -> [Decimal] { areaCalculator = fn(Integer width, Integer height) -> [Integer] {
rtn width.multiply(height); rtn width.multiply(height);
} }
``` ```
#### Concurrency Function (async)
```waddle
+proc fetchData(String url) -> [String] {
rtn my.network.get(url);
}
proc fetchData(String url) -> [String] {
rtn my.network.get(url);
}
-proc fetchData(String url) -> [String] {
rtn my.network.get(url);
}
```
### Error Handling ### Error Handling
#### Try/Catch (attempt->[ok, error])
```waddle ```waddle
result = riskyOperation().attempt { result = riskyOperation().attempt {
ok { ok {
@ -101,6 +123,29 @@ result = riskyOperation().attempt {
} }
} }
```
#### Custom error type declaration
```waddle
MathError {
message: String;
errorCode: Integer;
}
```
#### Function with explicit error handling
```waddle
+fn divide(Integer a, Integer b) -> [Decimal] fails with MathError {
if (b.eq(0)) {
my.error.fail(MathError("Division by zero", 1));
}
rtn a.divide(b);
}
```
### Resource Management / Context Management
```waddle
using DatabaseConnection db.set(connectionString) {
db.execute(query);
}
``` ```
### Iteration ### Iteration
@ -147,6 +192,27 @@ nums.each(
``` ```
### Boolean Expressions
#### Explicit Boolean Checks
```waddle
result = Boolean.and(
my.age.gt(18),
my.status.is(Verified)
);
```
#### Object Method Boolean Checks
```waddle
if(my.age.gt(18).and(my.status.is(Verified))){
my.age.gt(18),
my.status.is(Verified)
}
```
### Explicit Type Conversion
```waddle
String myString.set(my.number.set(42).as(String));
```
## Type System ## Type System
### Primitive Types ### Primitive Types