plum

#treesitter#compiler#wasm

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 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 FnOption[T] =
68
+ enum Parcel[T] =
69
- | FnSome(T)
69
+ | Delivered(T)
70
- | FnNone
70
+ | Lost
71
71
 
72
- fun unwrapFnOptionOr(o: FnOption, default: Int) -> Int =
72
+ fun contentsOr(p: Parcel, default: Int) -> Int =
73
- match o
73
+ match p
74
- FnSome(v) => v
74
+ Delivered(v) => v
75
- FnNone => default
75
+ Lost => default
76
76
 
77
77
  # `Str.length()` is not a real, working method — the point of this test is
78
- # that `FnOption$Str` coexists with `FnOption$Int` and both run correctly, not
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 unwrapFnOptionIntOr(o: FnOption, default: Int) -> Int =
80
+ fun intContentsOr(p: Parcel, default: Int) -> Int =
81
- match o
81
+ match p
82
- FnSome(v) => v
82
+ Delivered(v) => v
83
- FnNone => default
83
+ Lost => default
84
84
 
85
- fun unwrapFnOptionStrOr(o: FnOption, default: Int) -> Int =
85
+ fun strContentsOr(p: Parcel, default: Int) -> Int =
86
- match o
86
+ match p
87
- FnSome(v) => 4
87
+ Delivered(v) => 4
88
- FnNone => default
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 unwrapFnOptionOr(FnSome(13), 0) == 13
122
+ assert contentsOr(Delivered(13), 0) == 13
123
123
 
124
124
  test "generic enum multiple instantiations coexist and run correctly"
125
- assert unwrapFnOptionIntOr(FnSome(13), 0) + unwrapFnOptionStrOr(FnSome("abcd"), 0) == 17
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 unwrapFnOptionOr(FnSome(5), 0) + unwrapFnOptionOr(FnSome(37), 0) == 42
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 GenericOption[T] =
58
+ enum Reading[T] =
59
- | GSome(T)
59
+ | Sample(T)
60
- | GNone
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(GSome(v)) => v
68
+ GFull(Sample(v)) => v
69
- GFull(GNone) => -1
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(GSome(7))) == 7
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