Commit 1763e41
stdlib v2: first-class functions + harmonic variants + polish round (28 new builtins)
Three coherent tracks land together — language-level first-class
function values, OMNIcode-flavored harmonic operations, and the
ergonomic polish round Python users expect.
Track 1 — First-class functions (6 new HOFs):
Value::Function(String) is now a real Value variant. Bare function
names in expression context resolve to a function-value instead of
erroring as undefined variable. is_known_builtin + self.functions
HashMap handle resolution; call_first_class_function dispatches a
callable back through call_function via synthetic-arg variables
(same pattern as vm_call_builtin).
Six higher-order array operations:
arr_map(arr, fn) - apply fn per element
arr_filter(arr, pred) - keep where pred truthy
arr_reduce(arr, fn, init) - left fold
arr_any(arr, pred) - short-circuit OR
arr_all(arr, pred) - short-circuit AND
arr_find(arr, pred) - first matching element or null
Both user-defined functions AND built-ins work as values:
arr_map(xs, double) # user fn by bare name
arr_map(fibs, is_fibonacci) # built-in by bare name
Captured "function" is its definition, not a closure over local
scope. Proper closures = future work.
Track 2 — OMNIcode harmonic variants (6 new functions):
The architecturally distinctive piece. Anyone can write a file;
these write harmonically — operations that route through the
φ-math substrate to make decisions ordinary versions handle
naively.
harmonic_checksum(s)
Resonance signature: sum of per-char codepoint resonance.
harmonic_write_file(path, content)
Atomic write with a resonance gate. Computes mean per-char
resonance; commits via tmp+rename if score >= 0.5; rejects
below the gate (returns negative score). Threshold matches
value_danger's danger boundary.
harmonic_read_file(path)
Returns [content, mean_resonance] — caller decides whether
to trust low-coherence content.
harmonic_sort(arr)
Sort by harmony_value DESCENDING. Pure Fibonacci values
lead. Demo: [100, 89, 50, 144, 7, 233, 99] becomes
[89, 144, 233, 50, 99, 100, 7]. Different from arr_sort
(natural value ordering).
harmonic_split(s)
Chunk a string at Fibonacci-aligned word boundaries.
65-char string splits into [57, 8] (close to 55+8).
harmonic_partition(arr)
Group elements by nearest Fibonacci attractor. Returns
outer array of buckets in attractor order.
Track 3 — Polish round (8 new functions + 1 keyword tweak):
random_int(lo, hi), random_float(), random_seed(s)
xorshift64* PRNG, seeded from system nanos at interpreter
construction. random_seed(s) for deterministic runs.
println(x) — Display formatting (no HInt scaffolding)
print_raw(x) — Same, no trailing newline (progress lines)
str_pad_left(s, w, ch) / str_pad_right(s, w, ch)
Table-formatting workhorses.
arr_zip(a, b)
Pair elements positionally; shorter array sets length.
arr_unique(arr)
Dedupe preserving first-occurrence order. Type-aware via
values_equal (same as arr_contains uses).
Interpreter state grows by one field: rng_state: Cell<u64>. First
mutable-but-non-scope state since Phase O. Kept minimal —
Cell<u64> not Mutex because the interpreter is single-threaded.
Documentation:
- STDLIB.md updated comprehensively. ~135 named builtins now.
Alphabetical reference regenerated.
- "Missing on purpose" section updated: map/filter/reduce and
println/print_raw no longer missing.
- "Future-tense work" section updated: removed first-class
functions (done!) and random (done!); added closures-over-
local-scope and more harmonic variants as the next candidates.
New example files (3):
- examples/harmonic_variants.omc — exercises every harmonic_*
function with expected outputs in comments.
- examples/polish_round.omc — random determinism check,
println/print_raw demo, padding, zip, unique.
README:
- "What's proven right now" gains two rows (first-class
functions + harmonic variants).
- Host primitive count updated from ~100 to ~135.
Regression: V.9b ✓✓✓ FIXPOINTS unchanged. H.5 6/6 demos
converge. safe_keyword_host identical on tree-walk and OMC_VM=1.
All previous demos pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent daee499 commit 1763e41
8 files changed
Lines changed: 960 additions & 41 deletions
File tree
- examples
- omnimcode-core/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
7 | 79 | | |
8 | 80 | | |
9 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
148 | | - | |
| 150 | + | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
| |||
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
196 | | - | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| |||
0 commit comments