plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
00caf49
— Peter John
2026-11-01T16:43:14+05:30
T3: Map("a" => 1) examples + README
- README.md +2 -1
- plum-examples/generics.plum +2 -4
- plum-examples/maps.plum +28 -0
- plum-examples/seq.plum +1 -4
- plum-examples/values.plum +1 -2
README.md
CHANGED
|
@@ -946,7 +946,8 @@ hello, world!
|
|
|
946
946
|
- **`Buffer`** (`import std/Buffer`) — a growable, mutable byte sequence for building up a `Str`, amortized O(n) writes
|
|
947
947
|
- **`Array[T]`** (`import std/Array`) — the compiler-intrinsic generic array that `List` and `Map` are written on; `Grid[T]` is a flat 2D array
|
|
948
948
|
- **`List[T]`** (`import std/List`) — a growable list built on `Array`, with `get`/`add`/`set`/`removeAt`/`remove`/`sort`/`join`/`chunk` (iteration and transformation via `for`)
|
|
949
|
-
- **`Map[K, V]`**
|
|
949
|
+
- **`Map[K, V]`** (`import std/Map`) — `Map("a" => 1, "b" => 2)` builds a `Map[Str, Int]`; `Map[K, V]()` is empty. `k => v` is sugar for `Pair(k, v)` in any call's argument list, and a key can be any expression (`Map(n + 1 => x)`). A later duplicate key wins, as with `set`. See [`plum-examples/maps.plum`](plum-examples/maps.plum)
|
|
950
|
+
- **`Set[T]`**, **`Deque[T]`**, **`Heap[T]`** — a set over `Map`'s bucketed hash table, a ring-buffer double-ended queue and a key-ordered min-heap
|
|
950
951
|
- **`Seq[T]`** (`import std/Seq`) — the adapters and terminals of the `for` chains
|
|
951
952
|
- **`Json`**, **`Base64`**, **`Uuid`**, **`Time`**, **`Random`** — parsing, encoding, ids, wall-clock time and a seeded deterministic generator (`Random.float()` and `Random.intBelow(n)` use the wall clock)
|
|
952
953
|
- **`Os`**, **`Http`** — printing and the file system; HTTP requests through the host
|
plum-examples/generics.plum
CHANGED
|
@@ -152,10 +152,8 @@ test "Float specials survive an error-union payload with ? and catch"
|
|
|
152
152
|
# --- deep ----------------------------------------------------------------
|
|
153
153
|
|
|
154
154
|
test "List[List[Map[Str, Int]]] builds and reads back"
|
|
155
|
-
m1 := Map[Str, Int]()
|
|
156
|
-
m1
|
|
155
|
+
m1 := Map("ok" => 7)
|
|
157
|
-
m2 := Map[Str, Int]()
|
|
158
|
-
m2
|
|
156
|
+
m2 := Map("big" => 9223372036854775807)
|
|
159
157
|
inner1 := List[Map[Str, Int]]()
|
|
160
158
|
inner1.push(m1)
|
|
161
159
|
inner1.push(m2)
|
plum-examples/maps.plum
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Maps: building a `Map` from `key => value` pairs. `k => v` is sugar for
|
|
2
|
+
# `Pair(k, v)` in any call's argument list; later duplicate keys win.
|
|
3
|
+
import std/Int
|
|
4
|
+
import std/Str
|
|
5
|
+
import std/Map
|
|
6
|
+
|
|
7
|
+
test "maps_example_arrow_form"
|
|
8
|
+
m := Map("ann" => 3, "bob" => 5)
|
|
9
|
+
assert m.get("bob")! == 5
|
|
10
|
+
assert m.length() == 2
|
|
11
|
+
|
|
12
|
+
test "maps_mixed_pair_and_arrow"
|
|
13
|
+
assert Map(Pair("a", 1), "b" => 2).length() == 2
|
|
14
|
+
|
|
15
|
+
test "maps_duplicate_last_wins"
|
|
16
|
+
m := Map("a" => 1, "a" => 2)
|
|
17
|
+
assert m.get("a")! == 2
|
|
18
|
+
assert m.length() == 1
|
|
19
|
+
|
|
20
|
+
test "maps_nested"
|
|
21
|
+
m := Map("a" => Map("x" => 1))
|
|
22
|
+
assert m.get("a")!.get("x")! == 1
|
|
23
|
+
|
|
24
|
+
test "maps_int_keys"
|
|
25
|
+
assert Map(1 => "one", 2 => "two").get(1)! == "one"
|
|
26
|
+
|
|
27
|
+
test "maps_empty_with_explicit_generics"
|
|
28
|
+
assert Map[Str, Int]().isEmpty()
|
plum-examples/seq.plum
CHANGED
|
@@ -128,10 +128,7 @@ test "toList_no_body: a chain ends in a List without a for"
|
|
|
128
128
|
assert zs.length() == 5
|
|
129
129
|
|
|
130
130
|
test "Map keys feed Seq methods"
|
|
131
|
-
m := Map
|
|
131
|
+
m := Map(1 => 10, 2 => 20, 3 => 30)
|
|
132
|
-
m.set(1, 10)
|
|
133
|
-
m.set(2, 20)
|
|
134
|
-
m.set(3, 30)
|
|
135
132
|
big := for k := range m.keys().filter()
|
|
136
133
|
k > 1
|
|
137
134
|
assert big.length() == 2
|
plum-examples/values.plum
CHANGED
|
@@ -183,8 +183,7 @@ test "heap_field"
|
|
|
183
183
|
assert p.hp == 3
|
|
184
184
|
|
|
185
185
|
test "map_value"
|
|
186
|
-
m := Map[Str, Vec2]()
|
|
187
|
-
m
|
|
186
|
+
m := Map("a" => Vec2(x: 1.0, y: 2.0))
|
|
188
187
|
assert m.get("a")!.y == 2.0
|
|
189
188
|
|
|
190
189
|
test "nullable"
|