@grain/stdlib 0.5.12 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +200 -0
- package/LICENSE +1 -1
- package/README.md +25 -2
- package/array.gr +1512 -199
- package/array.md +2032 -94
- package/bigint.gr +239 -140
- package/bigint.md +450 -106
- package/buffer.gr +595 -102
- package/buffer.md +903 -145
- package/bytes.gr +401 -110
- package/bytes.md +551 -63
- package/char.gr +228 -49
- package/char.md +373 -7
- package/exception.gr +26 -12
- package/exception.md +29 -5
- package/float32.gr +130 -109
- package/float32.md +185 -57
- package/float64.gr +112 -99
- package/float64.md +185 -57
- package/hash.gr +47 -37
- package/hash.md +21 -3
- package/int16.gr +430 -0
- package/int16.md +618 -0
- package/int32.gr +200 -269
- package/int32.md +254 -289
- package/int64.gr +142 -225
- package/int64.md +254 -289
- package/int8.gr +511 -0
- package/int8.md +786 -0
- package/json.gr +2084 -0
- package/json.md +608 -0
- package/list.gr +120 -68
- package/list.md +125 -80
- package/map.gr +560 -57
- package/map.md +672 -56
- package/marshal.gr +239 -227
- package/marshal.md +36 -4
- package/number.gr +626 -676
- package/number.md +738 -153
- package/option.gr +33 -35
- package/option.md +58 -42
- package/package.json +2 -2
- package/path.gr +148 -187
- package/path.md +47 -96
- package/pervasives.gr +75 -416
- package/pervasives.md +85 -180
- package/priorityqueue.gr +433 -74
- package/priorityqueue.md +422 -54
- package/queue.gr +362 -80
- package/queue.md +433 -38
- package/random.gr +67 -75
- package/random.md +68 -40
- package/range.gr +135 -63
- package/range.md +198 -43
- package/rational.gr +284 -0
- package/rational.md +545 -0
- package/regex.gr +933 -1066
- package/regex.md +59 -60
- package/result.gr +23 -25
- package/result.md +54 -39
- package/runtime/atof/common.gr +78 -82
- package/runtime/atof/common.md +22 -10
- package/runtime/atof/decimal.gr +102 -127
- package/runtime/atof/decimal.md +28 -7
- package/runtime/atof/lemire.gr +56 -71
- package/runtime/atof/lemire.md +9 -1
- package/runtime/atof/parse.gr +83 -110
- package/runtime/atof/parse.md +12 -2
- package/runtime/atof/slow.gr +28 -35
- package/runtime/atof/slow.md +9 -1
- package/runtime/atof/table.gr +19 -18
- package/runtime/atof/table.md +10 -2
- package/runtime/atoi/parse.gr +153 -136
- package/runtime/atoi/parse.md +50 -1
- package/runtime/bigint.gr +410 -517
- package/runtime/bigint.md +71 -57
- package/runtime/compare.gr +176 -85
- package/runtime/compare.md +31 -1
- package/runtime/dataStructures.gr +144 -32
- package/runtime/dataStructures.md +267 -31
- package/runtime/debugPrint.gr +34 -15
- package/runtime/debugPrint.md +37 -5
- package/runtime/equal.gr +53 -52
- package/runtime/equal.md +30 -1
- package/runtime/exception.gr +38 -47
- package/runtime/exception.md +10 -8
- package/runtime/gc.gr +23 -152
- package/runtime/gc.md +13 -17
- package/runtime/malloc.gr +31 -31
- package/runtime/malloc.md +11 -3
- package/runtime/numberUtils.gr +191 -172
- package/runtime/numberUtils.md +17 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +540 -242
- package/runtime/string.md +76 -6
- package/runtime/unsafe/constants.gr +30 -13
- package/runtime/unsafe/constants.md +80 -0
- package/runtime/unsafe/conv.gr +55 -28
- package/runtime/unsafe/conv.md +41 -9
- package/runtime/unsafe/memory.gr +10 -30
- package/runtime/unsafe/memory.md +15 -19
- package/runtime/unsafe/tags.gr +37 -21
- package/runtime/unsafe/tags.md +88 -8
- package/runtime/unsafe/wasmf32.gr +30 -36
- package/runtime/unsafe/wasmf32.md +64 -56
- package/runtime/unsafe/wasmf64.gr +30 -36
- package/runtime/unsafe/wasmf64.md +64 -56
- package/runtime/unsafe/wasmi32.gr +49 -66
- package/runtime/unsafe/wasmi32.md +102 -94
- package/runtime/unsafe/wasmi64.gr +52 -79
- package/runtime/unsafe/wasmi64.md +108 -100
- package/runtime/utils/printing.gr +13 -15
- package/runtime/utils/printing.md +11 -3
- package/runtime/wasi.gr +294 -295
- package/runtime/wasi.md +62 -42
- package/set.gr +574 -64
- package/set.md +634 -54
- package/stack.gr +181 -64
- package/stack.md +271 -42
- package/string.gr +453 -533
- package/string.md +241 -151
- package/uint16.gr +369 -0
- package/uint16.md +585 -0
- package/uint32.gr +470 -0
- package/uint32.md +737 -0
- package/uint64.gr +471 -0
- package/uint64.md +737 -0
- package/uint8.gr +369 -0
- package/uint8.md +585 -0
- package/uri.gr +1093 -0
- package/uri.md +477 -0
- package/{sys → wasi}/file.gr +914 -500
- package/{sys → wasi}/file.md +454 -50
- package/wasi/process.gr +292 -0
- package/{sys → wasi}/process.md +164 -6
- package/wasi/random.gr +77 -0
- package/wasi/random.md +80 -0
- package/{sys → wasi}/time.gr +15 -22
- package/{sys → wasi}/time.md +5 -5
- package/immutablearray.gr +0 -929
- package/immutablearray.md +0 -1038
- package/immutablemap.gr +0 -493
- package/immutablemap.md +0 -479
- package/immutablepriorityqueue.gr +0 -360
- package/immutablepriorityqueue.md +0 -291
- package/immutableset.gr +0 -498
- package/immutableset.md +0 -449
- package/runtime/debug.gr +0 -2
- package/runtime/debug.md +0 -6
- package/runtime/unsafe/errors.gr +0 -36
- package/runtime/unsafe/errors.md +0 -204
- package/sys/process.gr +0 -254
- package/sys/random.gr +0 -79
- package/sys/random.md +0 -66
package/char.md
CHANGED
|
@@ -12,7 +12,19 @@ No other changes yet.
|
|
|
12
12
|
</details>
|
|
13
13
|
|
|
14
14
|
```grain
|
|
15
|
-
|
|
15
|
+
from "char" include Char
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```grain
|
|
19
|
+
'a'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```grain
|
|
23
|
+
'1'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```grain
|
|
27
|
+
'🌾'
|
|
16
28
|
```
|
|
17
29
|
|
|
18
30
|
## Values
|
|
@@ -53,7 +65,7 @@ No other changes yet.
|
|
|
53
65
|
</details>
|
|
54
66
|
|
|
55
67
|
```grain
|
|
56
|
-
isValid : Number
|
|
68
|
+
isValid : (charCode: Number) => Bool
|
|
57
69
|
```
|
|
58
70
|
|
|
59
71
|
Determines whether the given character code is a valid Unicode scalar value.
|
|
@@ -70,6 +82,16 @@ Returns:
|
|
|
70
82
|
|----|-----------|
|
|
71
83
|
|`Bool`|`true` if the number refers to a valid Unicode scalar value or `false` otherwise|
|
|
72
84
|
|
|
85
|
+
Examples:
|
|
86
|
+
|
|
87
|
+
```grain
|
|
88
|
+
Char.isValid(0) == true
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```grain
|
|
92
|
+
Char.isValid(-1) == false
|
|
93
|
+
```
|
|
94
|
+
|
|
73
95
|
### Char.**code**
|
|
74
96
|
|
|
75
97
|
<details disabled>
|
|
@@ -78,7 +100,7 @@ No other changes yet.
|
|
|
78
100
|
</details>
|
|
79
101
|
|
|
80
102
|
```grain
|
|
81
|
-
code : Char
|
|
103
|
+
code : (char: Char) => Number
|
|
82
104
|
```
|
|
83
105
|
|
|
84
106
|
Determines the Unicode scalar value for a character.
|
|
@@ -95,6 +117,16 @@ Returns:
|
|
|
95
117
|
|----|-----------|
|
|
96
118
|
|`Number`|The Unicode scalar value for the given character|
|
|
97
119
|
|
|
120
|
+
Examples:
|
|
121
|
+
|
|
122
|
+
```grain
|
|
123
|
+
Char.code('a') == 97
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```grain
|
|
127
|
+
Char.code('🌾') == 127806
|
|
128
|
+
```
|
|
129
|
+
|
|
98
130
|
### Char.**fromCode**
|
|
99
131
|
|
|
100
132
|
<details disabled>
|
|
@@ -103,7 +135,7 @@ No other changes yet.
|
|
|
103
135
|
</details>
|
|
104
136
|
|
|
105
137
|
```grain
|
|
106
|
-
fromCode : Number
|
|
138
|
+
fromCode : (usv: Number) => Char
|
|
107
139
|
```
|
|
108
140
|
|
|
109
141
|
Creates a character from the given Unicode scalar value.
|
|
@@ -126,6 +158,16 @@ Throws:
|
|
|
126
158
|
|
|
127
159
|
* When the Unicode scalar value is invalid
|
|
128
160
|
|
|
161
|
+
Examples:
|
|
162
|
+
|
|
163
|
+
```grain
|
|
164
|
+
Char.fromCode(97) == 'a'
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```grain
|
|
168
|
+
Char.fromCode(127806) == '🌾'
|
|
169
|
+
```
|
|
170
|
+
|
|
129
171
|
### Char.**succ**
|
|
130
172
|
|
|
131
173
|
<details disabled>
|
|
@@ -134,7 +176,7 @@ No other changes yet.
|
|
|
134
176
|
</details>
|
|
135
177
|
|
|
136
178
|
```grain
|
|
137
|
-
succ : Char
|
|
179
|
+
succ : (char: Char) => Char
|
|
138
180
|
```
|
|
139
181
|
|
|
140
182
|
Returns the next valid character by Unicode scalar value.
|
|
@@ -157,6 +199,16 @@ Throws:
|
|
|
157
199
|
|
|
158
200
|
* When the input character is the maximum valid Unicode scalar value
|
|
159
201
|
|
|
202
|
+
Examples:
|
|
203
|
+
|
|
204
|
+
```grain
|
|
205
|
+
Char.succ('a') == 'b'
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
```grain
|
|
209
|
+
Char.succ('1') == '2'
|
|
210
|
+
```
|
|
211
|
+
|
|
160
212
|
### Char.**pred**
|
|
161
213
|
|
|
162
214
|
<details disabled>
|
|
@@ -165,7 +217,7 @@ No other changes yet.
|
|
|
165
217
|
</details>
|
|
166
218
|
|
|
167
219
|
```grain
|
|
168
|
-
pred : Char
|
|
220
|
+
pred : (char: Char) => Char
|
|
169
221
|
```
|
|
170
222
|
|
|
171
223
|
Returns the previous valid character by Unicode scalar value.
|
|
@@ -188,6 +240,16 @@ Throws:
|
|
|
188
240
|
|
|
189
241
|
* When the input character is the minimum valid Unicode scalar value
|
|
190
242
|
|
|
243
|
+
Examples:
|
|
244
|
+
|
|
245
|
+
```grain
|
|
246
|
+
Char.pred('b') == 'a'
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
```grain
|
|
250
|
+
Char.pred('2') == '1'
|
|
251
|
+
```
|
|
252
|
+
|
|
191
253
|
### Char.**toString**
|
|
192
254
|
|
|
193
255
|
<details disabled>
|
|
@@ -196,7 +258,7 @@ No other changes yet.
|
|
|
196
258
|
</details>
|
|
197
259
|
|
|
198
260
|
```grain
|
|
199
|
-
toString : Char
|
|
261
|
+
toString : (char: Char) => String
|
|
200
262
|
```
|
|
201
263
|
|
|
202
264
|
Converts the given character to a string.
|
|
@@ -213,3 +275,307 @@ Returns:
|
|
|
213
275
|
|----|-----------|
|
|
214
276
|
|`String`|A string containing the given character|
|
|
215
277
|
|
|
278
|
+
Examples:
|
|
279
|
+
|
|
280
|
+
```grain
|
|
281
|
+
Char.toString('a') == "a"
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
```grain
|
|
285
|
+
Char.toString('🌾') == "🌾"
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Char.**(<)**
|
|
289
|
+
|
|
290
|
+
<details disabled>
|
|
291
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
292
|
+
No other changes yet.
|
|
293
|
+
</details>
|
|
294
|
+
|
|
295
|
+
```grain
|
|
296
|
+
(<) : (x: Char, y: Char) => Bool
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Checks if the first character is less than the second character by Unicode scalar value.
|
|
300
|
+
|
|
301
|
+
Parameters:
|
|
302
|
+
|
|
303
|
+
|param|type|description|
|
|
304
|
+
|-----|----|-----------|
|
|
305
|
+
|`x`|`Char`|The first character|
|
|
306
|
+
|`y`|`Char`|The second character|
|
|
307
|
+
|
|
308
|
+
Returns:
|
|
309
|
+
|
|
310
|
+
|type|description|
|
|
311
|
+
|----|-----------|
|
|
312
|
+
|`Bool`|`true` if the first character is less than the second character or `false` otherwise|
|
|
313
|
+
|
|
314
|
+
Examples:
|
|
315
|
+
|
|
316
|
+
```grain
|
|
317
|
+
use Char.{ (<) }
|
|
318
|
+
assert 'a' < 'b'
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
```grain
|
|
322
|
+
use Char.{ (<) }
|
|
323
|
+
assert '1' < '2'
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Char.**(<=)**
|
|
327
|
+
|
|
328
|
+
<details disabled>
|
|
329
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
330
|
+
No other changes yet.
|
|
331
|
+
</details>
|
|
332
|
+
|
|
333
|
+
```grain
|
|
334
|
+
(<=) : (x: Char, y: Char) => Bool
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Checks if the first character is less than or equal to the second character by Unicode scalar value.
|
|
338
|
+
|
|
339
|
+
Parameters:
|
|
340
|
+
|
|
341
|
+
|param|type|description|
|
|
342
|
+
|-----|----|-----------|
|
|
343
|
+
|`x`|`Char`|The first character|
|
|
344
|
+
|`y`|`Char`|The second character|
|
|
345
|
+
|
|
346
|
+
Returns:
|
|
347
|
+
|
|
348
|
+
|type|description|
|
|
349
|
+
|----|-----------|
|
|
350
|
+
|`Bool`|`true` if the first character is less than or equal to the second character or `false` otherwise|
|
|
351
|
+
|
|
352
|
+
Examples:
|
|
353
|
+
|
|
354
|
+
```grain
|
|
355
|
+
use Char.{ (<=) }
|
|
356
|
+
assert 'a' <= 'b'
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
```grain
|
|
360
|
+
use Char.{ (<=) }
|
|
361
|
+
assert '1' <= '2'
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
```grain
|
|
365
|
+
use Char.{ (<=) }
|
|
366
|
+
assert 'a' <= 'a'
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Char.**(>)**
|
|
370
|
+
|
|
371
|
+
<details disabled>
|
|
372
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
373
|
+
No other changes yet.
|
|
374
|
+
</details>
|
|
375
|
+
|
|
376
|
+
```grain
|
|
377
|
+
(>) : (x: Char, y: Char) => Bool
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
Checks if the first character is greater than the second character by Unicode scalar value.
|
|
381
|
+
|
|
382
|
+
Parameters:
|
|
383
|
+
|
|
384
|
+
|param|type|description|
|
|
385
|
+
|-----|----|-----------|
|
|
386
|
+
|`x`|`Char`|The first character|
|
|
387
|
+
|`y`|`Char`|The second character|
|
|
388
|
+
|
|
389
|
+
Returns:
|
|
390
|
+
|
|
391
|
+
|type|description|
|
|
392
|
+
|----|-----------|
|
|
393
|
+
|`Bool`|`true` if the first character is greater than the second character or `false` otherwise|
|
|
394
|
+
|
|
395
|
+
Examples:
|
|
396
|
+
|
|
397
|
+
```grain
|
|
398
|
+
use Char.{ (>) }
|
|
399
|
+
assert 'b' > 'a'
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
```grain
|
|
403
|
+
use Char.{ (>) }
|
|
404
|
+
assert '2' > '1'
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Char.**(>=)**
|
|
408
|
+
|
|
409
|
+
<details disabled>
|
|
410
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
411
|
+
No other changes yet.
|
|
412
|
+
</details>
|
|
413
|
+
|
|
414
|
+
```grain
|
|
415
|
+
(>=) : (x: Char, y: Char) => Bool
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Checks if the first character is greater than or equal to the second character by Unicode scalar value.
|
|
419
|
+
|
|
420
|
+
Parameters:
|
|
421
|
+
|
|
422
|
+
|param|type|description|
|
|
423
|
+
|-----|----|-----------|
|
|
424
|
+
|`x`|`Char`|The first character|
|
|
425
|
+
|`y`|`Char`|The second character|
|
|
426
|
+
|
|
427
|
+
Returns:
|
|
428
|
+
|
|
429
|
+
|type|description|
|
|
430
|
+
|----|-----------|
|
|
431
|
+
|`Bool`|`true` if the first character is greater than or equal to the second character or `false` otherwise|
|
|
432
|
+
|
|
433
|
+
Examples:
|
|
434
|
+
|
|
435
|
+
```grain
|
|
436
|
+
use Char.{ (>=) }
|
|
437
|
+
assert 'b' >= 'a'
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
```grain
|
|
441
|
+
use Char.{ (>=) }
|
|
442
|
+
assert '2' >= '1'
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
```grain
|
|
446
|
+
use Char.{ (>=) }
|
|
447
|
+
assert 'a' >= 'a'
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Char.**isAsciiDigit**
|
|
451
|
+
|
|
452
|
+
<details disabled>
|
|
453
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
454
|
+
No other changes yet.
|
|
455
|
+
</details>
|
|
456
|
+
|
|
457
|
+
```grain
|
|
458
|
+
isAsciiDigit : (char: Char) => Bool
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
Checks if the character is an ASCII digit.
|
|
462
|
+
|
|
463
|
+
Parameters:
|
|
464
|
+
|
|
465
|
+
|param|type|description|
|
|
466
|
+
|-----|----|-----------|
|
|
467
|
+
|`char`|`Char`|The character to check|
|
|
468
|
+
|
|
469
|
+
Returns:
|
|
470
|
+
|
|
471
|
+
|type|description|
|
|
472
|
+
|----|-----------|
|
|
473
|
+
|`Bool`|`true` if the character is an ASCII digit or `false` otherwise|
|
|
474
|
+
|
|
475
|
+
Examples:
|
|
476
|
+
|
|
477
|
+
```grain
|
|
478
|
+
assert Char.isAsciiDigit('1')
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
```grain
|
|
482
|
+
assert !Char.isAsciiDigit('a')
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Char.**isAsciiAlpha**
|
|
486
|
+
|
|
487
|
+
<details disabled>
|
|
488
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
489
|
+
No other changes yet.
|
|
490
|
+
</details>
|
|
491
|
+
|
|
492
|
+
```grain
|
|
493
|
+
isAsciiAlpha : (char: Char) => Bool
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
Checks if the character is an ASCII alphabetical character.
|
|
497
|
+
|
|
498
|
+
Parameters:
|
|
499
|
+
|
|
500
|
+
|param|type|description|
|
|
501
|
+
|-----|----|-----------|
|
|
502
|
+
|`char`|`Char`|The character to check|
|
|
503
|
+
|
|
504
|
+
Returns:
|
|
505
|
+
|
|
506
|
+
|type|description|
|
|
507
|
+
|----|-----------|
|
|
508
|
+
|`Bool`|`true` if the character is an ASCII alphabetical or `false` otherwise|
|
|
509
|
+
|
|
510
|
+
Examples:
|
|
511
|
+
|
|
512
|
+
```grain
|
|
513
|
+
assert Char.isAsciiAlpha('a')
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
```grain
|
|
517
|
+
assert !Char.isAsciiAlpha('1')
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### Char.**toAsciiLowercase**
|
|
521
|
+
|
|
522
|
+
<details disabled>
|
|
523
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
524
|
+
No other changes yet.
|
|
525
|
+
</details>
|
|
526
|
+
|
|
527
|
+
```grain
|
|
528
|
+
toAsciiLowercase : (char: Char) => Char
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
Converts the character to ASCII lowercase if it is an ASCII uppercase character.
|
|
532
|
+
|
|
533
|
+
Parameters:
|
|
534
|
+
|
|
535
|
+
|param|type|description|
|
|
536
|
+
|-----|----|-----------|
|
|
537
|
+
|`char`|`Char`|The character to convert|
|
|
538
|
+
|
|
539
|
+
Returns:
|
|
540
|
+
|
|
541
|
+
|type|description|
|
|
542
|
+
|----|-----------|
|
|
543
|
+
|`Char`|The lowercased character|
|
|
544
|
+
|
|
545
|
+
Examples:
|
|
546
|
+
|
|
547
|
+
```grain
|
|
548
|
+
assert Char.toAsciiLowercase('B') == 'b'
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
### Char.**toAsciiUppercase**
|
|
552
|
+
|
|
553
|
+
<details disabled>
|
|
554
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
555
|
+
No other changes yet.
|
|
556
|
+
</details>
|
|
557
|
+
|
|
558
|
+
```grain
|
|
559
|
+
toAsciiUppercase : (char: Char) => Char
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
Converts the character to ASCII uppercase if it is an ASCII lowercase character.
|
|
563
|
+
|
|
564
|
+
Parameters:
|
|
565
|
+
|
|
566
|
+
|param|type|description|
|
|
567
|
+
|-----|----|-----------|
|
|
568
|
+
|`char`|`Char`|The character to convert|
|
|
569
|
+
|
|
570
|
+
Returns:
|
|
571
|
+
|
|
572
|
+
|type|description|
|
|
573
|
+
|----|-----------|
|
|
574
|
+
|`Char`|The uppercased character|
|
|
575
|
+
|
|
576
|
+
Examples:
|
|
577
|
+
|
|
578
|
+
```grain
|
|
579
|
+
assert Char.toAsciiUppercase('b') == 'B'
|
|
580
|
+
```
|
|
581
|
+
|
package/exception.gr
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utilities for working with the Exception type.
|
|
3
3
|
*
|
|
4
|
-
* The Exception type represents an error that has
|
|
4
|
+
* The Exception type represents an error that has occurred during computation.
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
6
|
+
* @example from "exception" include Exception
|
|
7
7
|
*
|
|
8
|
-
* @
|
|
8
|
+
* @example exception ExampleError(Number)
|
|
9
|
+
* @example exception ExampleError
|
|
10
|
+
*
|
|
11
|
+
* @since v0.3.0
|
|
9
12
|
*/
|
|
13
|
+
module Exception
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @section Values: Functions included in the Exception module.
|
|
17
|
-
*/
|
|
15
|
+
from "runtime/unsafe/wasmi32" include WasmI32
|
|
16
|
+
from "runtime/unsafe/memory" include Memory
|
|
17
|
+
from "runtime/exception" include Exception
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Registers an exception printer. When an exception is thrown, all registered
|
|
@@ -23,10 +23,24 @@ import Exception from "runtime/exception"
|
|
|
23
23
|
* used as the exception's string value.
|
|
24
24
|
*
|
|
25
25
|
* @param printer: The exception printer to register
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* exception ExampleError(Number)
|
|
29
|
+
*
|
|
30
|
+
* Exception.registerPrinter(e => {
|
|
31
|
+
* match (e) {
|
|
32
|
+
* ExampleError(lineNumber) =>
|
|
33
|
+
* Some("Error found on line: " ++ toString(lineNumber)),
|
|
34
|
+
* _ => None,
|
|
35
|
+
* }
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* throw ExampleError(1) // Error found on line: 1
|
|
39
|
+
*
|
|
26
40
|
* @since v0.3.0
|
|
27
41
|
*/
|
|
28
42
|
@disableGC
|
|
29
|
-
|
|
43
|
+
provide let rec registerPrinter = (printer: Exception => Option<String>) => {
|
|
30
44
|
// This function _must_ be @disableGC because the printer list uses
|
|
31
45
|
// unsafe types. Not really a memory leak as this list is never collected
|
|
32
46
|
|
package/exception.md
CHANGED
|
@@ -4,7 +4,7 @@ title: Exception
|
|
|
4
4
|
|
|
5
5
|
Utilities for working with the Exception type.
|
|
6
6
|
|
|
7
|
-
The Exception type represents an error that has
|
|
7
|
+
The Exception type represents an error that has occurred during computation.
|
|
8
8
|
|
|
9
9
|
<details disabled>
|
|
10
10
|
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
@@ -12,12 +12,20 @@ No other changes yet.
|
|
|
12
12
|
</details>
|
|
13
13
|
|
|
14
14
|
```grain
|
|
15
|
-
|
|
15
|
+
from "exception" include Exception
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```grain
|
|
19
|
+
exception ExampleError(Number)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```grain
|
|
23
|
+
exception ExampleError
|
|
16
24
|
```
|
|
17
25
|
|
|
18
26
|
## Values
|
|
19
27
|
|
|
20
|
-
Functions included in the Exception module.
|
|
28
|
+
Functions and constants included in the Exception module.
|
|
21
29
|
|
|
22
30
|
### Exception.**registerPrinter**
|
|
23
31
|
|
|
@@ -27,7 +35,7 @@ No other changes yet.
|
|
|
27
35
|
</details>
|
|
28
36
|
|
|
29
37
|
```grain
|
|
30
|
-
registerPrinter : (Exception
|
|
38
|
+
registerPrinter : (printer: (Exception => Option<String>)) => Void
|
|
31
39
|
```
|
|
32
40
|
|
|
33
41
|
Registers an exception printer. When an exception is thrown, all registered
|
|
@@ -39,5 +47,21 @@ Parameters:
|
|
|
39
47
|
|
|
40
48
|
|param|type|description|
|
|
41
49
|
|-----|----|-----------|
|
|
42
|
-
|`printer`|`Exception
|
|
50
|
+
|`printer`|`Exception => Option<String>`|The exception printer to register|
|
|
51
|
+
|
|
52
|
+
Examples:
|
|
53
|
+
|
|
54
|
+
```grain
|
|
55
|
+
exception ExampleError(Number)
|
|
56
|
+
|
|
57
|
+
Exception.registerPrinter(e => {
|
|
58
|
+
match (e) {
|
|
59
|
+
ExampleError(lineNumber) =>
|
|
60
|
+
Some("Error found on line: " ++ toString(lineNumber)),
|
|
61
|
+
_ => None,
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
throw ExampleError(1) // Error found on line: 1
|
|
66
|
+
```
|
|
43
67
|
|