plum

#treesitter#compiler#wasm

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

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


c459df0 — Peter John 2026-11-11T00:02:15+05:30
std: one equality method, eq; equals is gone from Slice, List, Time, Duration and Uuid
compiler/core/src/prune.rs CHANGED
@@ -18,9 +18,9 @@ use std::fmt::Write;
18
18
 
19
19
  /// Method names the compiler calls with no call site in the source: interpolation, a
20
20
  /// constructor's `init`, hashing and equality, the operators, the frame entry.
21
- const IMPLICIT: [&str; 19] = [
21
+ const IMPLICIT: [&str; 18] = [
22
22
  "concat",
23
- "toStr", "init", "equals", "hash", "compare", "drop", "add", "sub", "mul", "div", "neg", "eq", "lt", "le", "gt",
23
+ "toStr", "init", "hash", "compare", "drop", "add", "sub", "mul", "div", "neg", "eq", "lt", "le", "gt",
24
24
  "ge", "update", "draw",
25
25
  ];
26
26
 
compiler/core/src/uniqueness.rs CHANGED
@@ -447,8 +447,8 @@ fn varName(e: &Expr) -> Option<&str> {
447
447
  /// Method names the compiler may call without a visible call site (interpolation,
448
448
  /// constructors, hashing, the operators `a + b`, `-a`, `a == b`, `a < b`): their `self` and
449
449
  /// parameters are never proved.
450
- const IMPLICIT: [&str; 16] = [
450
+ const IMPLICIT: [&str; 15] = [
451
- "toStr", "init", "equals", "hash", "compare", "drop", "add", "sub", "mul", "div", "neg", "eq", "lt", "le", "gt",
451
+ "toStr", "init", "hash", "compare", "drop", "add", "sub", "mul", "div", "neg", "eq", "lt", "le", "gt",
452
452
  "ge",
453
453
  ];
454
454
 
compiler/wasm-codegen/src/matching.rs CHANGED
@@ -1238,7 +1238,7 @@ pub(crate) fn plumTypeFromValtypeHint(vt: ValType) -> PlumType {
1238
1238
  /// checker's `op_calls` entry is shared by every instantiation of a generic body, so
1239
1239
  /// the operand's type in THIS unit decides.
1240
1240
  /// `==`/`!=` keep their built-in meaning on a type with no `eq` (as the checker decides
1241
- /// per operand type): `h != h2` in `List<T>.equals` calls `eq` for `List<List<Int>>` and
1241
+ /// per operand type): `h != h2` in `List<T>.eq` calls `eq` for `List<List<Int>>` and
1242
1242
  /// not for `List<Pt>`.
1243
1243
  pub(crate) fn isOpCall(expr: &ast::Expr, operand: &ast::Expr, ctx: &LocalCtx) -> bool {
1244
1244
  let Some(call) = ctx.op_calls.get(&expr.id) else { return false };
examples/recursion.plum CHANGED
@@ -173,7 +173,7 @@ test "reverse_append"
173
173
  assert xs.get(0).unwrapOr(-1) == 3
174
174
  assert xs.get(2).unwrapOr(-1) == 1
175
175
  ys := [1, 2].append([3, 4])
176
- assert ys.equals([1, 2, 3, 4])
176
+ assert ys.eq([1, 2, 3, 4])
177
177
 
178
178
  test "for_range"
179
179
  total := Tally(n: 0)
@@ -187,8 +187,8 @@ test "for_range"
187
187
 
188
188
  test "to_slice_round_trip"
189
189
  s := [1, 2, 3].map(|x| x * 2).toSlice()
190
- assert s.equals([2, 4, 6].toSlice())
190
+ assert s.eq([2, 4, 6].toSlice())
191
- assert List.fromSlice(s).equals([2, 4, 6])
191
+ assert List.fromSlice(s).eq([2, 4, 6])
192
192
 
193
193
  test "to_array"
194
194
  a := [7, 8, 9].toArray()
@@ -207,10 +207,10 @@ test "cons_fold_million"
207
207
  assert xs.reverse().get(0).unwrapOr(-1) == 999999
208
208
 
209
209
  test "equals_and_toStr"
210
- assert [1, 2, 3].equals([1, 2, 3])
210
+ assert [1, 2, 3].eq([1, 2, 3])
211
- assert ![1, 2, 3].equals([1, 2])
211
+ assert ![1, 2, 3].eq([1, 2])
212
- assert ![1, 2].equals([1, 2, 3])
212
+ assert ![1, 2].eq([1, 2, 3])
213
- assert ![1, 2, 3].equals([1, 2, 4])
213
+ assert ![1, 2, 3].eq([1, 2, 4])
214
214
  assert [1, 2, 3].toStr() == "[1,2,3]"
215
215
 
216
216
  # ==== own list tests ====
std/Slice.plum CHANGED
@@ -110,13 +110,10 @@ struct Slice<T>(mut data: Array<T>, mut start: Int, mut size: Int, mut cap: Int)
110
110
  fun length(self) -> Int =
111
111
  self.size
112
112
 
113
- # `==` and `!=`: the same length and the elements `==` in order (see `equals`). Without
113
+ # `==` and `!=`: the same length and the elements `==` in order. Without it `==` on two
114
- # it `==` on two slices would ask whether they are the same object.
114
+ # slices would ask whether they are the same object. For a struct `T` without its own
115
- fun eq(self, other: Slice<T>) -> Bool = self.equals(other)
116
-
117
- # Elementwise comparison via `==`; for a struct `T` without its own `eq`, `==` is
118
- # reference identity (the same object), not field-by-field equality.
115
+ # `eq`, the elements' `==` is reference identity (the same object).
119
- fun equals(self, other: Slice<T>) -> Bool =
116
+ fun eq(self, other: Slice<T>) -> Bool =
120
117
  self.length() == other.length() && self.sameFrom(other, 0)
121
118
 
122
119
  # Whether `self` and `other` (same length) agree from index `i` on.
@@ -477,8 +474,8 @@ test "list equals compares elementwise"
477
474
  c := Slice<Int>()
478
475
  c.push(1)
479
476
  c.push(2)
480
- assert a.equals(b)
477
+ assert a.eq(b)
481
- assert !a.equals(c)
478
+ assert !a.eq(c)
482
479
 
483
480
  test "list sort orders elements correctly"
484
481
  l := Slice<Int>()
@@ -633,7 +630,7 @@ test "every method indexes from the view's start"
633
630
  w.push(5)
634
631
  w.push(3)
635
632
  w.push(7)
636
- assert v.equals(w)
633
+ assert v.eq(w)
637
634
  assert v.sublist(1, 3).toStr() == "[5,3]"
638
635
  assert v.drop(2).toStr() == "[3,7]"
639
636
  assert v.chunk(3).length() == 2
std/Time.plum CHANGED
@@ -40,10 +40,7 @@ struct Time(value: Int) =
40
40
  fun isAfter(self, other: Time) -> Bool =
41
41
  self.value > other.value
42
42
 
43
- fun equals(self, other: Time) -> Bool =
44
- self.value == other.value
45
-
46
- # `==` and `!=`: `equals`.
43
+ # `==` and `!=`: the same value.
47
44
  fun eq(self, other: Time) -> Bool = self.value == other.value
48
45
 
49
46
  # The proleptic-Gregorian calendar date this instant falls on, in UTC.
@@ -161,10 +158,7 @@ struct Duration(value: Int) =
161
158
  fun isAfter(self, other: Duration) -> Bool =
162
159
  self.value > other.value
163
160
 
164
- fun equals(self, other: Duration) -> Bool =
165
- self.value == other.value
166
-
167
- # `==` and `!=`: `equals`.
161
+ # `==` and `!=`: the same value.
168
162
  fun eq(self, other: Duration) -> Bool = self.value == other.value
169
163
 
170
164
  test "Time.toStr formats the epoch as ISO 8601 in UTC"
std/Uuid.plum CHANGED
@@ -17,10 +17,7 @@ struct Uuid(value: Str) =
17
17
  fun toStr(self) -> Str =
18
18
  self.value
19
19
 
20
- fun equals(self, other: Uuid) -> Bool =
21
- self.value == other.value
22
-
23
- # `==` and `!=`: `equals`.
20
+ # `==` and `!=`: the same value.
24
21
  fun eq(self, other: Uuid) -> Bool = self.value == other.value
25
22
 
26
23
  fun isNil(self) -> Bool =
@@ -153,12 +150,12 @@ test "fromStr rejects malformed input"
153
150
  assert Uuid.isValid("550e8400-e29b-41d4-a716-44665544000") == false
154
151
  assert Uuid.isValid("550e8400xe29b-41d4-a716-446655440000") == false
155
152
 
156
- test "equals compares by value"
153
+ test "eq compares by value"
157
154
  a := Uuid(value: "550e8400-e29b-41d4-a716-446655440000")
158
155
  b := Uuid(value: "550e8400-e29b-41d4-a716-446655440000")
159
- assert a.equals(b) == true
156
+ assert a.eq(b) == true
160
- assert a.equals(Uuid.nil()) == false
157
+ assert a.eq(Uuid.nil()) == false
161
158
 
162
- test "== is equals"
159
+ test "== is eq"
163
160
  a := Uuid.fromStr("123e4567-e89b-12d3-a456-426614174000")!
164
161
  assert a == Uuid.fromStr("123E4567-E89B-12D3-A456-426614174000")! && a != Uuid.nil()
std/collections/FenwickTree.plum CHANGED
@@ -254,7 +254,7 @@ test "ofList, get, set and toList"
254
254
  g := f.set(2, 10)
255
255
  assert g.get(2)! == 10
256
256
  assert g.prefixSum(5) == 21
257
- assert g.toList().equals([5, 1, 10, 2, 3])
257
+ assert g.toList().eq([5, 1, 10, 2, 3])
258
258
  assert fenValid(g)
259
259
 
260
260
  test "edge cases: empty tree, out of range and clamped ranges"
@@ -292,9 +292,9 @@ test "persistence: old versions answer old queries"
292
292
  assert c.prefixSum(3) == 7
293
293
  assert b.rangeSum(2, 3) == 0
294
294
  assert c.rangeSum(2, 3) == 5
295
- assert a.toList().equals([0, 0, 0])
295
+ assert a.toList().eq([0, 0, 0])
296
- assert b.toList().equals([0, 7, 0])
296
+ assert b.toList().eq([0, 7, 0])
297
- assert c.toList().equals([0, 2, 5])
297
+ assert c.toList().eq([0, 2, 5])
298
298
  assert fenValid(a) && fenValid(b) && fenValid(c)
299
299
 
300
300
  test "invariants_after_random_ops: adds and sets match a brute-force slice"
@@ -328,7 +328,7 @@ test "invariants_after_random_ops: adds and sets match a brute-force slice"
328
328
  assert st.f.prefixSum(i) == st.pre
329
329
  if i < n
330
330
  st.pre = st.pre + brute.at(i)
331
- assert st.f.toList().equals(List.fromSlice(brute))
331
+ assert st.f.toList().eq(List.fromSlice(brute))
332
332
 
333
333
  test "ofList matches repeated add on 10,000 elements, and old versions keep their sums"
334
334
  n := 10000
@@ -352,7 +352,7 @@ test "ofList matches repeated add on 10,000 elements, and old versions keep thei
352
352
  c := a.set(0, 0).add(n - 1, 5)
353
353
  assert c.prefixSum(n) == st.pre - xs.at(0) + 5
354
354
  assert a.prefixSum(n) == st.pre
355
- assert a.toList().equals(List.fromSlice(xs))
355
+ assert a.toList().eq(List.fromSlice(xs))
356
356
 
357
357
  test "ofSize shares its nodes: a huge size with alternating bits builds in O(log n)"
358
358
  # 0b1010...10 (50 bits): unshared halves made ~4e10 nodes and ran out of memory.
std/collections/LeftistHeap.plum CHANGED
@@ -250,8 +250,8 @@ test "heapsort of pseudo-random lists matches Slice.sort"
250
250
  xs := lhRandList(300, seed * 7919)
251
251
  h := lhPushAll(lhInts(), xs)
252
252
  assert lhValid(h)
253
- assert h.toList().equals(lhSorted(xs))
253
+ assert h.toList().eq(lhSorted(xs))
254
- assert LeftistHeap.fromList(xs, |a, b| a < b).toList().equals(lhSorted(xs))
254
+ assert LeftistHeap.fromList(xs, |a, b| a < b).toList().eq(lhSorted(xs))
255
255
 
256
256
  test "fromList builds a valid heap"
257
257
  h := LeftistHeap.fromList([4, 1, 3, 1, 5, 9, 2, 6], |a, b| a < b)
@@ -272,7 +272,7 @@ test "merge two heaps"
272
272
  assert m.length() == 350
273
273
  assert lhValid(m)
274
274
  all := lhRandList(200, 3).append(lhRandList(150, 4))
275
- assert m.toList().equals(lhSorted(all))
275
+ assert m.toList().eq(lhSorted(all))
276
276
  assert a.merge(lhInts()).toStr() == a.toStr()
277
277
  assert lhInts().merge(a).toStr() == a.toStr()
278
278
  assert a.length() == 200 && b.length() == 150
@@ -325,7 +325,7 @@ test "invariants hold through pseudo-random pushes and pops"
325
325
  assert lhValid(s.h)
326
326
  assert s.h.length() == model.length()
327
327
  assert lhValid(s.h)
328
- assert s.h.toList().equals(List.fromSlice(model.sort(|a, b| a < b)))
328
+ assert s.h.toList().eq(List.fromSlice(model.sort(|a, b| a < b)))
329
329
 
330
330
  test "100,000 pushes then pops come out sorted"
331
331
  s := LhRun(h: lhInts(), x: 99)
std/collections/List.plum CHANGED
@@ -119,15 +119,12 @@ enum List<T> =
119
119
  fun toStr(self) -> Str =
120
120
  "[{self.join(",")}]"
121
121
 
122
- # `==` and `!=`: the elements compare equal, in order (see `equals`).
122
+ # `==` and `!=`: the elements compare equal (`==`), in order.
123
- fun eq(self, other: List<T>) -> Bool = self.equals(other)
124
-
125
- # Elementwise comparison via `==`.
126
- fun equals(self, other: List<T>) -> Bool = match self
123
+ fun eq(self, other: List<T>) -> Bool = match self
127
124
  Nil => other.isEmpty()
128
125
  Cons(h, t) => match other
129
126
  Nil => false
130
- Cons(h2, t2) => if h != h2 then false else t.equals(t2)
127
+ Cons(h2, t2) => if h != h2 then false else t.eq(t2)
131
128
 
132
129
  # `fromSlice`'s loop: conses `xs[i]`, `xs[i-1]`, ... down to index 0 onto `out`.
133
130
  fun consFrom<A>(xs: Slice<A>, i: Int, out: List<A>) -> List<A> =
std/collections/PairingHeap.plum CHANGED
@@ -253,7 +253,7 @@ test "heapsort of pseudo-random lists matches Slice.sort"
253
253
  xs := phRandList(300, seed * 7919)
254
254
  h := phPushAll(phInts(), xs)
255
255
  assert phValid(h)
256
- assert h.toList().equals(phSorted(xs))
256
+ assert h.toList().eq(phSorted(xs))
257
257
 
258
258
  test "fromList builds a valid heap"
259
259
  h := PairingHeap.fromList([4, 1, 3, 1, 5, 9, 2, 6], |a, b| a < b)
@@ -270,7 +270,7 @@ test "merge two heaps"
270
270
  assert m.length() == 350
271
271
  assert phValid(m)
272
272
  all := phRandList(200, 3).append(phRandList(150, 4))
273
- assert m.toList().equals(phSorted(all))
273
+ assert m.toList().eq(phSorted(all))
274
274
  assert a.merge(phInts()).toStr() == a.toStr()
275
275
  assert phInts().merge(a).toStr() == a.toStr()
276
276
  assert a.length() == 200 && b.length() == 150
@@ -323,7 +323,7 @@ test "invariants hold through pseudo-random pushes and pops"
323
323
  assert phValid(s.h)
324
324
  assert s.h.length() == model.length()
325
325
  assert phValid(s.h)
326
- assert s.h.toList().equals(List.fromSlice(model.sort(|a, b| a < b)))
326
+ assert s.h.toList().eq(List.fromSlice(model.sort(|a, b| a < b)))
327
327
 
328
328
  test "10,000 inserts then repeated deleteMin"
329
329
  h := phPushAll(phInts(), phRandList(10000, 5))
std/collections/SegmentTree.plum CHANGED
@@ -274,16 +274,16 @@ test "sum tree: query, get, set, length and all"
274
274
  assert u.get(3)! == 10
275
275
  assert u.query(3, 5) == 13
276
276
  assert u.all() == 23
277
- assert u.toList().equals([5, 1, 4, 10, 3])
277
+ assert u.toList().eq([5, 1, 4, 10, 3])
278
278
  assert segValid(u)
279
279
 
280
280
  test "update applies a function to one element"
281
281
  s := segSum([1, 2, 3, 4])
282
282
  u := s.update(2, |x| x * 10).update(0, |x| x - 1)
283
- assert u.toList().equals([0, 2, 30, 4])
283
+ assert u.toList().eq([0, 2, 30, 4])
284
284
  assert u.all() == 36
285
285
  assert u.query(1, 3) == 32
286
- assert s.update(4, |x| x + 1).toList().equals(s.toList())
286
+ assert s.update(4, |x| x + 1).toList().eq(s.toList())
287
287
  assert s.update(-1, |x| x + 1).all() == 10
288
288
  assert segValid(u)
289
289
 
@@ -324,7 +324,7 @@ test "ofSize starts at identity, and ofList over a product"
324
324
  w := z.set(5, 4).set(0, 1)
325
325
  assert w.query(0, 6) == 5
326
326
  assert w.query(1, 5) == 0
327
- assert w.toList().equals([1, 0, 0, 0, 0, 4])
327
+ assert w.toList().eq([1, 0, 0, 0, 0, 4])
328
328
  assert segValid(w)
329
329
  assert z.all() == 0
330
330
 
@@ -362,9 +362,9 @@ test "persistence: old versions answer old queries"
362
362
  assert c.all() == 7
363
363
  assert b.query(2, 3) == 0
364
364
  assert c.query(2, 3) == 5
365
- assert a.toList().equals([0, 0, 0])
365
+ assert a.toList().eq([0, 0, 0])
366
- assert b.toList().equals([0, 7, 0])
366
+ assert b.toList().eq([0, 7, 0])
367
- assert c.toList().equals([0, 2, 5])
367
+ assert c.toList().eq([0, 2, 5])
368
368
  assert segValid(a) && segValid(b) && segValid(c)
369
369
 
370
370
  test "invariants_after_random_ops: sets and queries match brute force for sum, min, max and concat"
@@ -400,7 +400,7 @@ test "invariants_after_random_ops: sets and queries match brute force for sum, m
400
400
  assert st.mx.query(lo, hi) == want.mx
401
401
  assert st.cat.query(lo, hi) == want.cat
402
402
  assert segValid(st.sum)
403
- assert st.sum.toList().equals(List.fromSlice(brute))
403
+ assert st.sum.toList().eq(List.fromSlice(brute))
404
404
 
405
405
  test "10,000 elements: build, every prefix, random updates and the old version"
406
406
  n := 10000
@@ -428,10 +428,10 @@ test "10,000 elements: build, every prefix, random updates and the old version"
428
428
  _ := xs.set(j, v)
429
429
  seed.s = seed.s.set(j, v)
430
430
  assert seed.s.all() == seed.pre
431
- assert seed.s.toList().equals(List.fromSlice(xs))
431
+ assert seed.s.toList().eq(List.fromSlice(xs))
432
432
  assert segValid(seed.s)
433
433
  assert first.all() == firstAll
434
- assert first.toList().equals(firstList)
434
+ assert first.toList().eq(firstList)
435
435
 
436
436
  test "ofList over struct elements"
437
437
  vs := Cons(head: Vec2(x: 1.0, y: 2.0), tail: Cons(head: Vec2(x: 3.0, y: 4.0), tail: Cons(head: Vec2(x: 5.0, y: 6.0), tail: Nil)))
std/testing.plum CHANGED
@@ -25,14 +25,12 @@ import std/Result
25
25
  # `unwrapOr` (`r.unwrapOr(0)`, `r!`); `expectFailureNamed` also checks which error it is
26
26
  # (the error enum provides `fun name(self) -> Str`).
27
27
  #
28
- # CAVEAT on `expectEq`/`expectNotEq`/`expectObject`/`Slice.equals`: Plum's
28
+ # CAVEAT on `expectEq`/`expectNotEq`/`expectObject`/`expectArray`: `==`/`!=`
29
- # `==`/`!=` have no operator-overloading mechanism. For Int/Str/Bool/Float
29
+ # call the type's `eq(self, other)` method when it has one (Int/Str/Bool/Float,
30
- # they do real value comparison (Str is content-compared, not
31
- # reference-compared). For class/enum instances there is no such override,
30
+ # `Slice`, `List`, `Map`, `Uuid`, `Time`, ...). A struct or enum without an
32
- # so `==` compiles to reference identity — `expectEq` on two
31
+ # `eq` compares by reference identity, so `expectEq` on two
33
- # separately-constructed-but-equal structs will wrongly report `false`. For
32
+ # separately-constructed-but-equal values of such a type reports `false`:
34
- # those types, prefer the type's own `equals(self, other)` method (e.g.
35
- # `Uuid.equals`, `Time.equals`) directly in `assert` instead.
33
+ # give the type an `eq`.
36
34
 
37
35
  fun expectTrue(cond: Bool) -> Bool =
38
36
  cond
@@ -53,9 +51,9 @@ fun expectObject<T>(a: T, b: T) -> Bool =
53
51
  a == b
54
52
 
55
53
  # Elementwise `Slice<T>` comparison — see the module-level CAVEAT above for
56
- # what `Slice.equals`'s own `==` means when `T` is a class/enum.
54
+ # what the elements' `==` means when `T` is a struct/enum.
57
55
  fun expectArray<T>(a: Slice<T>, b: Slice<T>) -> Bool =
58
- a.equals(b)
56
+ a.eq(b)
59
57
 
60
58
  fun expectSuccess<T, E>(r: Result<T, E>) -> Bool = match r
61
59
  Ok(_) => true
@@ -88,12 +86,12 @@ test "expectEq and expectNotEq"
88
86
  assert expectEq("ab".concat("c"), "abc")
89
87
  assert expectNotEq(2 + 2, 5)
90
88
 
91
- test "list equality via the Slice.equals method"
89
+ test "list equality via the Slice.eq method"
92
90
  a := [1, 2, 3].toSlice()
93
91
  b := [1, 2, 3].toSlice()
94
92
  c := [1, 2].toSlice()
95
- assert a.equals(b)
93
+ assert a.eq(b)
96
- assert expectFalse(a.equals(c))
94
+ assert expectFalse(a.eq(c))
97
95
 
98
96
  test "Results are inspected with unwrapOr and !"
99
97
  ok: Result<Int, Oops> := Ok(5)