~repos /plum

#treesitter#compiler#wasm

git clone https://pyrossh.dev/repos/plum.git

A statically typed, imperative programming language inspired by rust, python


ed5fe02e pyrossh

1 year ago
docs
Files changed (1) hide show
  1. readme.md +21 -3
readme.md CHANGED
@@ -74,7 +74,7 @@ fn (s Temperature) to_str() =
74
74
 
75
75
 
76
76
  group("Cat Record") |g|
77
- test "talks" |t|
77
+ test("talks") |t|
78
78
  c := Cat(name = "123", age = 1)
79
79
  c.talk()
80
80
 
@@ -106,7 +106,7 @@ for,while,if,then,else,end,record,enum,fn,assert,when,match
106
106
 
107
107
  ### Types
108
108
  ```
109
- nil, any, bool, byte, int, float, dec, str, time, duration
109
+ nil, any, bool, byte, int, float, dec, str, time, duration, regex, uuid
110
110
  [] for lists list[int], list[list[int]]
111
111
  [] for maps map[int], map[map[int]]
112
112
  ? for optional int? str?
@@ -114,12 +114,15 @@ nil, any, bool, byte, int, float, dec, str, time, duration
114
114
  ```
115
115
 
116
116
  **nil**
117
+
117
118
  The nil type is used to represent types that are nilable
118
119
 
119
120
  **any**
121
+
120
122
  The any type is an empty trait and is used to represent all types
121
123
 
122
124
  **bool**
125
+
123
126
  A bool can be either `true` or `false`. It is used in logical operations and conditional statements.
124
127
 
125
128
  ```rb
@@ -131,6 +134,7 @@ end
131
134
  ```
132
135
 
133
136
  **byte**
137
+
134
138
  A byte represents an unsigned 8 bit number. It is mainly used to represent strings and binary data.
135
139
  ```rs
136
140
  let data: []byte?
@@ -138,6 +142,7 @@ data = [104, 101, 197, 130, 197, 130, 111, 0]
138
142
  ```
139
143
 
140
144
  **int**
145
+
141
146
  An int is a signed 64 bit number. It can be represented in various ways,
142
147
  0b - Binary (Base 2)
143
148
  0x - Hexadecimal (Base 16)
@@ -154,9 +159,11 @@ An int is a signed 64 bit number. It can be represented in various ways,
154
159
  ```
155
160
 
156
161
  **float**
162
+
157
163
  A float represents a 64-bit floating point (52-bit mantissa) IEEE-754-2008 binary64
158
164
 
159
165
  **str**
166
+
160
167
  A str represents a slice of runes or unicode code points. It is encoded to UTF-8 by default.
161
168
  It supports interpolation of variables/values that implement the ToStr interface.
162
169
 
@@ -172,7 +179,8 @@ println("Name ${name} age ${age}")
172
179
  **list**
173
180
 
174
181
  ```
175
- a := [1, 2, 3]
182
+ a := [1, 2, 3] // list[int]
183
+ b := [[1, 2], [3, 4], [5, 6]] // list[list[int]]
176
184
  ```
177
185
 
178
186
  **map**
@@ -197,6 +205,7 @@ tree = [
197
205
 
198
206
 
199
207
  **Assignment statement**
208
+ ```
200
209
  low, mid, high := 0, 0, n.numItems
201
210
  x := 10
202
211
  y := 20
@@ -205,8 +214,11 @@ xy_map := [x: x, y: y]
205
214
  assoc_list = [a: 1, b: 2]
206
215
  assoc_list[:a]
207
216
  assoc_list["b"]
217
+ ```
208
218
 
209
219
  **While statement**
220
+
221
+ ```
210
222
  while low < high
211
223
  mid = (low + high) / 2
212
224
  low = cmp > 0 > mid + 1 : low
@@ -218,8 +230,10 @@ while (eventuallyErrorSequence()) |value| {
218
230
  sum1 += value;
219
231
  else |err|
220
232
  try expect(err == error.ReachedZero);
233
+ ```
221
234
 
222
235
  **For statement**
236
+ ```
223
237
  for players_list |value|
224
238
  if value == 0
225
239
  continue
@@ -253,6 +267,7 @@ fn range(start: int, end: int, cb: (v: T) -> IterateResult) =
253
267
  range(0, 5, |v| =>
254
268
  sum3 += v
255
269
  )
270
+ ```
256
271
 
257
272
  // Iterate over multiple objects.
258
273
  // All lengths must be equal at the start of the loop, otherwise detectable
@@ -261,10 +276,13 @@ for items, items2 |i, j|
261
276
  count += i + j
262
277
 
263
278
  **When expression/statement**
279
+
280
+ ```
264
281
  when
265
282
  cmp > 0 -> low = mid + 1
266
283
  cmp < 0 -> high = mid
267
284
  cmp == 0 -> return mid, true
285
+ ```
268
286
 
269
287
  Arithmetic (+, -, /, *, @divFloor, @sqrt, @ceil, @log, etc.)
270
288
  Bitwise operators (>>, <<, &, |, ~, etc.)