Compare commits

..

2 commits

3 changed files with 78 additions and 15 deletions

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

View file

@ -1,5 +1,4 @@
<type_declaration> ::= <identifier> <type_declaration> ::= <inherited_type>
["/" <identifier>]?
["->" <interface_identifier_list>]? ["->" <interface_identifier_list>]?
"{" <class_body> "}" "{" <class_body> "}"
@ -9,9 +8,11 @@
| <constructor_declaration> | <constructor_declaration>
| <destructor_declaration>)* | <destructor_declaration>)*
<type_inheritance> ::= "extends" <identifier> <inherited_type> ::= [<parent> "/"]? <child>
<generic_type_declaration> ::= <identifier> "<" <type_parameter_list> ">" <parent> ::= <identifier>
<child> ::= <identifier>
<type_parameter_list> ::= <identifier> ("," <identifier>)* <type_parameter_list> ::= <identifier> ("," <identifier>)*

View file

@ -12,10 +12,6 @@
<interface_method_signature> ::= <interface_method_signature> ::=
<accessibility_modifier>"fn" <identifier> <function_signature> <accessibility_modifier>"fn" <identifier> <function_signature>
<generic_interface_declaration> ::=
"@" <interface_identifier> "<" <type_parameter_list> ">"
"{" <interface_body> "}"
<interface_inheritance> ::= <interface_inheritance> ::=
"@" <interface_identifier> "extends" <interface_identifier_list> "@" <interface_identifier> "extends" <interface_identifier_list>
"{" <interface_body> "}" "{" <interface_body> "}"