plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
4ac8d64
— Peter John
2026-10-25T17:25:35+05:30
docs(examples): replace Option-like example enums with Parcel/Reading
- plum-examples/functions.plum +19 -19
- plum-examples/match.plum +6 -6
plum-examples/functions.plum
CHANGED
|
@@ -65,27 +65,27 @@ enum GenericBox2[T] =
|
|
|
65
65
|
fun doubled(value: T) -> Int =
|
|
66
66
|
identity(value) + identity(value)
|
|
67
67
|
|
|
68
|
-
enum
|
|
68
|
+
enum Parcel[T] =
|
|
69
|
-
|
|
|
69
|
+
| Delivered(T)
|
|
70
|
-
|
|
|
70
|
+
| Lost
|
|
71
71
|
|
|
72
|
-
fun
|
|
72
|
+
fun contentsOr(p: Parcel, default: Int) -> Int =
|
|
73
|
-
match
|
|
73
|
+
match p
|
|
74
|
-
|
|
74
|
+
Delivered(v) => v
|
|
75
|
-
|
|
75
|
+
Lost => default
|
|
76
76
|
|
|
77
77
|
# `Str.length()` is not a real, working method — the point of this test is
|
|
78
|
-
# that `
|
|
78
|
+
# that `Parcel$Str` coexists with `Parcel$Int` and both run correctly, not
|
|
79
79
|
# string processing, so the Str arm returns a fixed literal.
|
|
80
|
-
fun
|
|
80
|
+
fun intContentsOr(p: Parcel, default: Int) -> Int =
|
|
81
|
-
match
|
|
81
|
+
match p
|
|
82
|
-
|
|
82
|
+
Delivered(v) => v
|
|
83
|
-
|
|
83
|
+
Lost => default
|
|
84
84
|
|
|
85
|
-
fun
|
|
85
|
+
fun strContentsOr(p: Parcel, default: Int) -> Int =
|
|
86
|
-
match
|
|
86
|
+
match p
|
|
87
|
-
|
|
87
|
+
Delivered(v) => 4
|
|
88
|
-
|
|
88
|
+
Lost => default
|
|
89
89
|
|
|
90
90
|
enum GenericBox3[T] =
|
|
91
91
|
| GenericBox3(value: T)
|
|
@@ -119,13 +119,13 @@ test "transitively generic call chain runs correctly"
|
|
|
119
119
|
assert doubled(21) == 42
|
|
120
120
|
|
|
121
121
|
test "generic enum specialized and matched runs correctly"
|
|
122
|
-
assert
|
|
122
|
+
assert contentsOr(Delivered(13), 0) == 13
|
|
123
123
|
|
|
124
124
|
test "generic enum multiple instantiations coexist and run correctly"
|
|
125
|
-
assert
|
|
125
|
+
assert intContentsOr(Delivered(13), 0) + strContentsOr(Delivered("abcd"), 0) == 17
|
|
126
126
|
|
|
127
127
|
test "same bare generic enum param function called multiple times runs correctly"
|
|
128
|
-
assert
|
|
128
|
+
assert contentsOr(Delivered(5), 0) + contentsOr(Delivered(37), 0) == 42
|
|
129
129
|
|
|
130
130
|
test "ordinary function with bare generic class param runs correctly"
|
|
131
131
|
assert sumBox(GenericBox3(value: 11)) == 11
|
plum-examples/match.plum
CHANGED
|
@@ -55,9 +55,9 @@ fun unwrapNested(n: Nested) -> Int =
|
|
|
55
55
|
Wrap(Absent) => -1
|
|
56
56
|
Empty => 0
|
|
57
57
|
|
|
58
|
-
enum
|
|
58
|
+
enum Reading[T] =
|
|
59
|
-
|
|
|
59
|
+
| Sample(T)
|
|
60
|
-
|
|
|
60
|
+
| NoSignal
|
|
61
61
|
|
|
62
62
|
enum GenericBox[T] =
|
|
63
63
|
| GFull(T)
|
|
@@ -65,8 +65,8 @@ enum GenericBox[T] =
|
|
|
65
65
|
|
|
66
66
|
fun unwrapGenericBox(b: GenericBox) -> Int =
|
|
67
67
|
match b
|
|
68
|
-
GFull(
|
|
68
|
+
GFull(Sample(v)) => v
|
|
69
|
-
GFull(
|
|
69
|
+
GFull(NoSignal) => -1
|
|
70
70
|
GEmpty => 0
|
|
71
71
|
|
|
72
72
|
enum RecOption =
|
|
@@ -176,7 +176,7 @@ test "nested constructor pattern mismatch falls through to next case runs correc
|
|
|
176
176
|
assert unwrapNested(Wrap(Absent)) == -1
|
|
177
177
|
|
|
178
178
|
test "nested constructor pattern against a specialized generic enum runs correctly"
|
|
179
|
-
assert unwrapGenericBox(GFull(
|
|
179
|
+
assert unwrapGenericBox(GFull(Sample(7))) == 7
|
|
180
180
|
|
|
181
181
|
test "doubly nested constructor pattern runs correctly"
|
|
182
182
|
assert unwrapTwice(RSome(RSome(RNone))) == 1
|