~repos /plum
git clone https://pyrossh.dev/repos/plum.git
A statically typed, imperative programming language inspired by rust, python
c8e41654
—
pyrossh 1 year ago
docs
readme.md
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
# 👾 Pacos Programming Language
|
|
2
|
+
|
|
3
|
+
A simple statically typed imperative programming language. Its main aim to be simple and easy to code correct programs. It takes inspiration for golang and ponylang. It comes packed with linting, formatting, test runner, language server, package management in-built.
|
|
2
4
|
|
|
5
|
+
The parser is written using tree-sitter syntax so has out of the box syntax highlighting support for helix and zed editor.
|
|
6
|
+
|
|
3
|
-
|
|
7
|
+
Here is some sample syntax, enjoy 👾
|
|
4
8
|
```
|
|
9
|
+
module lambda
|
|
10
|
+
|
|
5
|
-
|
|
11
|
+
fn sum(a: int, b: int): int = a + b
|
|
6
12
|
|
|
7
13
|
fn sum_list(series: list[int]): int =
|
|
8
14
|
series.reduce(0, |v| v + 1)
|
|
@@ -32,31 +38,22 @@ record Cat(
|
|
|
32
38
|
age: int
|
|
33
39
|
)
|
|
34
40
|
|
|
35
|
-
fn Cat.
|
|
41
|
+
fn Cat.with_name(name: str) =
|
|
36
42
|
Cat(name: name, age: 0)
|
|
37
43
|
|
|
38
44
|
fn (c: Cat) fullname(): str =
|
|
39
45
|
c.name + c.age.to_str()
|
|
40
46
|
|
|
47
|
+
fn (c: Cat) talk() =
|
|
48
|
+
println("cat ${c.name} says meow")
|
|
49
|
+
|
|
41
50
|
fn (c: Cat) to_str(): str =
|
|
42
|
-
"Cat<{c.fullname()}>"
|
|
51
|
+
"Cat<{c.fullname()}, ${c.age}>"
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
|
|
45
|
-
c := Cat(name = "123", age = 1)
|
|
46
|
-
c.talk()
|
|
47
|
-
Cat("rabby", 21).fullname() == "rabby21"
|
|
48
|
-
c2 := Cat(...c, age: c.age + 1)
|
|
49
|
-
|
|
50
|
-
[Cat("Molly", 9), Cat("Fenton", 6)]
|
|
51
|
-
.retain(|p| p.name.size > 5)
|
|
52
|
-
.map(|p| describe(p))
|
|
53
|
-
.each(|d| println(d))
|
|
54
|
-
// → cat Fenton is 6 years of age
|
|
55
|
-
)
|
|
56
53
|
|
|
57
54
|
type MapCallback = fn(v: a): v
|
|
58
55
|
|
|
59
|
-
trait Comparable
|
|
56
|
+
trait Comparable(
|
|
60
57
|
fn compare(left: A, right: A): bool
|
|
61
58
|
)
|
|
62
59
|
|
|
@@ -64,18 +61,6 @@ trait ToStr(
|
|
|
64
61
|
fn to_str(): str
|
|
65
62
|
)
|
|
66
63
|
|
|
67
|
-
struct Cat(name: str, age: int) =
|
|
68
|
-
fn fullname() =
|
|
69
|
-
name + age.str()
|
|
70
|
-
|
|
71
|
-
fn talk() =
|
|
72
|
-
println("cat ${name} says meow")
|
|
73
|
-
|
|
74
|
-
#[ToStr]
|
|
75
|
-
fn to_str(self): str =
|
|
76
|
-
"Cat<{self.fullname()}>"
|
|
77
|
-
|
|
78
|
-
|
|
79
64
|
enum Temperature =
|
|
80
65
|
| celsius(float)
|
|
81
66
|
| fahrenheit(float)
|
|
@@ -87,56 +72,67 @@ fn (s Temperature) to_str() =
|
|
|
87
72
|
fahrenheit(t) && t > 86 -> "${t}F is above 86 fahrenheit"
|
|
88
73
|
fahrenheit(t) -> "${t}F is below 86 fahrenheit"
|
|
89
74
|
|
|
90
|
-
test "enum ordinal value" {
|
|
91
|
-
expect(Value.zero).to_equal(0);
|
|
92
|
-
expect(Value.one).to_equal(1);
|
|
93
|
-
expect(Value.two).to_equal(2);
|
|
94
|
-
}
|
|
95
75
|
|
|
76
|
+
group("Cat Record") |g|
|
|
96
|
-
test
|
|
77
|
+
test "talks" |t|
|
|
97
|
-
expect(Value.zero).to_equal(0);
|
|
98
|
-
|
|
78
|
+
c := Cat(name = "123", age = 1)
|
|
99
|
-
|
|
79
|
+
c.talk()
|
|
100
|
-
}
|
|
101
80
|
|
|
102
|
-
|
|
81
|
+
test("fullname") |t|
|
|
82
|
+
Cat("rabby", 21).fullname() == "rabby21"
|
|
103
|
-
|
|
83
|
+
c2 := Cat(...c, age: c.age + 1)
|
|
104
84
|
|
|
85
|
+
test("to_str") |t|
|
|
86
|
+
items := [Cat("Molly", 9), Cat("Fenton", 6)]
|
|
87
|
+
.retain(|p| p.name.size > 5)
|
|
88
|
+
.map(|p| describe(p))
|
|
89
|
+
.each(|d| println(d))
|
|
90
|
+
assert items[0].to_str() == "Cat<Fenton, 6>"
|
|
91
|
+
|
|
92
|
+
test("enum ordinal value") |t|
|
|
93
|
+
expect(Value.zero).to_equal(0)
|
|
94
|
+
expect(Value.one).to_equal(1)
|
|
95
|
+
expect(Value.two).to_equal(2)
|
|
96
|
+
|
|
105
|
-
bench("1231") |t, n|
|
|
97
|
+
bench("1231") |t, n|
|
|
98
|
+
for 0..n |i|
|
|
106
|
-
|
|
99
|
+
println(i)
|
|
107
100
|
```
|
|
108
101
|
|
|
109
102
|
## Language Reference
|
|
110
103
|
|
|
111
104
|
**Keywords**
|
|
112
|
-
|
|
105
|
+
for,while,if,then,else,end,record,enum,fn,assert,when,match
|
|
113
106
|
|
|
114
|
-
|
|
107
|
+
### Types
|
|
108
|
+
```
|
|
115
|
-
bool, byte, int, float, dec, str, time, duration
|
|
109
|
+
nil, any, bool, byte, int, float, dec, str, time, duration
|
|
116
110
|
[] for lists list[int], list[list[int]]
|
|
117
111
|
[] for maps map[int], map[map[int]]
|
|
118
112
|
? for optional int? str?
|
|
119
113
|
! for return error types int!, str!
|
|
120
|
-
nil for optional assignment and pointers
|
|
121
|
-
|
|
122
|
-
|
|
114
|
+
```
|
|
123
115
|
|
|
124
116
|
**nil**
|
|
125
|
-
|
|
117
|
+
The nil type is used to represent types that are nilable
|
|
118
|
+
|
|
119
|
+
**any**
|
|
120
|
+
The any type is an empty trait and is used to represent all types
|
|
126
121
|
|
|
127
122
|
**bool**
|
|
128
123
|
A bool can be either `true` or `false`. It is used in logical operations and conditional statements.
|
|
129
124
|
|
|
130
|
-
```
|
|
125
|
+
```rb
|
|
131
126
|
assert true != false
|
|
132
127
|
|
|
133
|
-
if true || false
|
|
128
|
+
if true || false then
|
|
134
129
|
print("works")
|
|
130
|
+
end
|
|
135
131
|
```
|
|
136
132
|
|
|
137
133
|
**byte**
|
|
138
134
|
A byte represents an unsigned 8 bit number. It is mainly used to represent strings and binary data.
|
|
139
|
-
```
|
|
135
|
+
```rs
|
|
140
136
|
let data: []byte?
|
|
141
137
|
data = [104, 101, 197, 130, 197, 130, 111, 0]
|
|
142
138
|
```
|
|
@@ -200,7 +196,7 @@ tree = [
|
|
|
200
196
|
```
|
|
201
197
|
|
|
202
198
|
|
|
203
|
-
**Assignment
|
|
199
|
+
**Assignment statement**
|
|
204
200
|
low, mid, high := 0, 0, n.numItems
|
|
205
201
|
x := 10
|
|
206
202
|
y := 20
|
|
@@ -218,8 +214,6 @@ while low < high
|
|
|
218
214
|
if cmp == 0
|
|
219
215
|
return mid, true
|
|
220
216
|
|
|
221
|
-
while (i < 10) : (i += 1) {}
|
|
222
|
-
|
|
223
217
|
while (eventuallyErrorSequence()) |value| {
|
|
224
218
|
sum1 += value;
|
|
225
219
|
else |err|
|
|
@@ -284,7 +278,7 @@ if (a) |value| {
|
|
|
284
278
|
unreachable;
|
|
285
279
|
}
|
|
286
280
|
|
|
287
|
-
###
|
|
281
|
+
### Conditional operators
|
|
288
282
|
|
|
289
283
|
**not operator**
|
|
290
284
|
!a
|