Update README.md and add examples/ directory
This commit is contained in:
parent
689034a522
commit
eba473c0d9
47
README.md
47
README.md
@ -20,6 +20,15 @@ b: int = 0;
|
|||||||
c: str; // declared, but not yet assigned
|
c: str; // declared, but not yet assigned
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Expressions
|
||||||
|
|
||||||
|
```
|
||||||
|
a: int = 34;
|
||||||
|
b: int = 35;
|
||||||
|
c: int = 1;
|
||||||
|
d: int = a + b * c; // with correct operator precedence
|
||||||
|
```
|
||||||
|
|
||||||
## Structs
|
## Structs
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -29,10 +38,10 @@ struct MyStruct {
|
|||||||
field3: SomeOtherStruct
|
field3: SomeOtherStruct
|
||||||
}
|
}
|
||||||
|
|
||||||
my_struct: MyStruct = MyStruct{
|
my_struct: MyStruct = MyStruct.{
|
||||||
field1=1,
|
field1=1,
|
||||||
field2="Hello, World!",
|
field2="Hello, World!",
|
||||||
field3=SomeOtherStruct{...} // whatever SomeOtherStruct takes
|
field3=SomeOtherStruct.{...} // whatever SomeOtherStruct takes
|
||||||
};
|
};
|
||||||
|
|
||||||
my_struct.field1 = 2;
|
my_struct.field1 = 2;
|
||||||
@ -55,12 +64,12 @@ enum Weekday {
|
|||||||
day: Weekday = Weekday.Tuesday;
|
day: Weekday = Weekday.Tuesday;
|
||||||
|
|
||||||
match day in {
|
match day in {
|
||||||
case Monday do { ... }
|
case Monday { ... } // handle Monday
|
||||||
case Tuesday do { ... }
|
case Tuesday { ... } // handle Tuesday
|
||||||
case Wednesday do { ... }
|
case Wednesday { ... } // and so on...
|
||||||
case Thursday do { ... }
|
case Thursday { ... }
|
||||||
case Friday do { ... }
|
case Friday { ... }
|
||||||
case _ do { ... } // default
|
case _ { ... } // default
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
or
|
or
|
||||||
@ -73,8 +82,8 @@ enum IntResult {
|
|||||||
result: IntResult = IntResult.Ok(5);
|
result: IntResult = IntResult.Ok(5);
|
||||||
|
|
||||||
match result in {
|
match result in {
|
||||||
case Ok(num) do { ... } // num is defined in this scope
|
case Ok(num) { ... } // num is defined in this scope
|
||||||
case Err(err) do { ... } // similarly err is defined in this scope
|
case Err(err) { ... } // similarly err is defined in this scope
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Currently, polymorphic structs/enums are not supported, however I plan to eventually do so.
|
Currently, polymorphic structs/enums are not supported, however I plan to eventually do so.
|
||||||
@ -98,10 +107,28 @@ the_min: int = min(5, 10);
|
|||||||
|
|
||||||
## Arrays
|
## Arrays
|
||||||
|
|
||||||
|
```
|
||||||
|
numbers: int[] = [:int, 0, 1, 2, 3, 4]; // array literal must state element type (for now)
|
||||||
|
numbers = [:int, 2*x for x in numbers]; // list comprehension must also (for now)
|
||||||
|
```
|
||||||
|
|
||||||
## For loops
|
## For loops
|
||||||
|
|
||||||
|
```
|
||||||
|
// prints numbers 0-9
|
||||||
|
for i in range(0, 10) {
|
||||||
|
print(int_to_str(i)+"\n");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## While loops
|
## While loops
|
||||||
|
|
||||||
|
a: int = 0;
|
||||||
|
while a < 10 {
|
||||||
|
print(int_to_str(a)+"\n");
|
||||||
|
a = a + 1;
|
||||||
|
}
|
||||||
|
|
||||||
## Reading files
|
## Reading files
|
||||||
|
|
||||||
## Importing
|
## Importing
|
||||||
|
5
examples/numbers.ppp
Normal file
5
examples/numbers.ppp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
numbers: int[] = [:int, 0, 1, 2, 3, 4, 5];
|
||||||
|
|
||||||
|
numbers = [:int, 2*x for x in numbers];
|
||||||
|
|
||||||
|
for number in numbers print(int_to_str(number)+"\n");
|
11
examples/person.ppp
Normal file
11
examples/person.ppp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
struct Person {
|
||||||
|
age: int,
|
||||||
|
name: str
|
||||||
|
}
|
||||||
|
|
||||||
|
my_person: Person = Person.{
|
||||||
|
age=50,
|
||||||
|
name="Hello, World"
|
||||||
|
};
|
||||||
|
|
||||||
|
print(int_to_str(my_person.age)+" "+my_person.name+"\n");
|
21
examples/weekday.ppp
Normal file
21
examples/weekday.ppp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
enum Weekday {
|
||||||
|
Monday,
|
||||||
|
Tuesday,
|
||||||
|
Wednesday,
|
||||||
|
Thursday,
|
||||||
|
Friday,
|
||||||
|
Saturday,
|
||||||
|
Sunday
|
||||||
|
}
|
||||||
|
|
||||||
|
day: Weekday = Weekday.Monday;
|
||||||
|
|
||||||
|
match day {
|
||||||
|
case Monday print("It's Monday!\n");
|
||||||
|
case Tuesday print("It's Tuesday!\n");
|
||||||
|
case Wednesday print("It's Wednesday!\n");
|
||||||
|
case Thursday print("It's Thursday!\n");
|
||||||
|
case Friday print("It's Friday!\n");
|
||||||
|
case Saturday print("It's Saturday!\n");
|
||||||
|
case Sunday print("It's Sunday!\n");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user