Compare commits

..

No commits in common. "ca6d83636180dd829c2a4d4c332b11de9c32f5a0" and "e72d8835f8aa298b4584c59d2cd9816b62c85fc7" have entirely different histories.

3 changed files with 15 additions and 78 deletions

View file

@ -54,57 +54,35 @@ Animal/Dog -> [Mammal, Domesticated] {
#### Function declaration #### Function declaration
##### Public function (+fn) ##### Public function
```waddle ```waddle
+fn calculateArea(Integer width, Integer height) -> [Integer] { +fn calculateArea(width: Integer, height: Integer) -> [Decimal] {
rtn width.multiply(height); rtn width.multiply(height);
} }
``` ```
##### Protected Function (fn) ##### Protected Function
```waddle ```waddle
fn calculateArea(Integer width, Integer height) -> [Integer] { fn calculateArea(width: Integer, height: Integer) -> [Decimal] {
rtn width.multiply(height); rtn width.multiply(height);
} }
``` ```
##### Private Function (-fn) ##### Private Function
```waddle ```waddle
-fn calculateArea(Integer width, Integer height) -> [Integer] { -fn calculateArea(width: Integer, height: Integer) -> [Decimal] {
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(Integer width, Integer height) -> [Integer] { areaCalculator = fn(width: Integer, height: Integer) -> [Decimal] {
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 {
@ -123,29 +101,6 @@ 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
@ -192,27 +147,6 @@ 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,4 +1,5 @@
<type_declaration> ::= <inherited_type> <type_declaration> ::= <identifier>
["/" <identifier>]?
["->" <interface_identifier_list>]? ["->" <interface_identifier_list>]?
"{" <class_body> "}" "{" <class_body> "}"
@ -8,11 +9,9 @@
| <constructor_declaration> | <constructor_declaration>
| <destructor_declaration>)* | <destructor_declaration>)*
<inherited_type> ::= [<parent> "/"]? <child> <type_inheritance> ::= "extends" <identifier>
<parent> ::= <identifier> <generic_type_declaration> ::= <identifier> "<" <type_parameter_list> ">"
<child> ::= <identifier>
<type_parameter_list> ::= <identifier> ("," <identifier>)* <type_parameter_list> ::= <identifier> ("," <identifier>)*

View file

@ -12,6 +12,10 @@
<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> "}"