Commit Graph

47 Commits

Author SHA1 Message Date
80dac0051d apl: perf — fix quadratic append in permutations, restore queens(8)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 43s
apl-permutations was doing (append acc <new-perms>) which is
O(|acc|) and acc grows ~N! big — total cost O(N!²).

Swapped to (append <new-perms> acc) — append is O(|first|)
so cost is O((n+1)·N!_prev) per layer, total O(N!).  q(7)
went from 32s to 12s; q(8)=92 now finishes well within the
300s timeout, so the queens(8) test is restored.

497/497.  Phase 8 complete.
2026-05-07 19:33:09 +00:00
b661318a45 apl: train/fork notation (f g h) and (g h) (+6 tests, 496/496)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s
Parser: when a parenthesised subexpression contains only function
segments (>= 2), collect-segments-loop now emits a :train AST node
instead of treating it as a value-producing expression.

Resolver: apl-resolve-{monadic,dyadic} handle :train.
- monadic 2-train (atop):  (g h)⍵ = g (h ⍵)
- monadic 3-train (fork):  (f g h)⍵ = (f ⍵) g (h ⍵)
- dyadic 2-train:          ⍺(g h)⍵ = g (⍺ h ⍵)
- dyadic 3-train:          ⍺(f g h)⍵ = (⍺ f ⍵) g (⍺ h ⍵)

apl-run "(+/÷≢) 1 2 3 4 5"  → 3   (mean)
apl-run "(- ⌊) 5"           → -5  (atop)
apl-run "2 (+ × -) 5"       → -21 (dyadic fork)
apl-run "(⌈/-⌊/) 3 1 4 …"   → 8   (range)
2026-05-07 19:02:17 +00:00
a677585639 apl: programs-e2e + ⌿/⍀ glyph fix (+15 tests, 490/490)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
programs-e2e.sx exercises the classic-algorithm shapes from
lib/apl/tests/programs/*.apl via the full pipeline (apl-run on
embedded source strings).  Tests include factorial-via-∇,
triangular numbers, sum-of-squares, prime-mask building blocks
(divisor counts via outer mod), named-fn composition,
dyadic max-of-two, and a single Newton sqrt step.

The original one-liners (e.g. primes' inline ⍵←⍳⍵) need parser
features we haven't built (compress-as-fn, inline assign) — the
e2e tests use multi-statement equivalents.  No file-reading
primitive in OCaml SX, so source is embedded.

Side-fix: ⌿ (first-axis reduce) and ⍀ (first-axis scan) were
silently skipped by the tokenizer — added to apl-glyph-set
and apl-parse-op-glyphs.
2026-05-07 18:31:57 +00:00
c04f38a1ba apl: multi-axis bracket A[I;J] / A[I;] / A[;J] (+8 tests, 475/475)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
Parser: split-bracket-content splits inner tokens on :semi at
depth 0; maybe-bracket emits (:bracket arr axis-exprs...) for
multi-axis access, with :all marker for empty axes.

Runtime: apl-bracket-multi enumerates index combinations via
apl-cartesian (helper) and produces sub-array. Scalar axes
collapse from result shape; vector / nil axes contribute their
length.

apl-run "M ← (3 3) ⍴ ⍳9 ⋄ M[2;2]"  → 5
apl-run "M ← (3 3) ⍴ ⍳9 ⋄ M[1;]"   → 1 2 3
apl-run "M ← (3 3) ⍴ ⍳9 ⋄ M[;2]"   → 2 5 8
apl-run "M ← (2 3) ⍴ ⍳6 ⋄ M[1 2;1 2]" → 2x2 sub-block
2026-05-07 17:56:24 +00:00
b13819c50c apl: named function definitions f ← {…} (+7 tests, 467/467)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
Parser: apl-collect-fn-bindings pre-scans stmt-groups for
`name ← { ... }` patterns and populates apl-known-fn-names.
is-fn-tok? consults this list; collect-segments-loop emits
(:fn-name nm) for known names so they parse as functions.

Resolver: apl-resolve-{monadic,dyadic} handle :fn-name by
looking up env, asserting the binding is a dfn, returning
a closure that dispatches to apl-call-dfn{-m,}.

Recursion still works: `fact ← {0=⍵:1 ⋄ ⍵×∇⍵-1} ⋄ fact 5` → 120.
2026-05-07 17:33:41 +00:00
d9cf00f287 apl: quick-wins bundle — decimals + ⎕← + strings (+10 tests, 460/460)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 49s
Three small unblockers in one iteration:
- tokenizer: read-digits! now consumes optional ".digits" suffix,
  so 3.7 and ¯2.5 are single number tokens.
- tokenizer: ⎕ followed by ← emits a single :name "⎕←" token
  (instead of splitting on the assign glyph).  Parser registers
  ⎕← in apl-quad-fn-names; apl-monadic-fn maps to apl-quad-print.
- eval-ast: :str AST nodes evaluate to char arrays.  Single-char
  strings become rank-0 scalars; multi-char become rank-1 vectors
  of single-char strings.
2026-05-07 17:26:37 +00:00
0dd2fa3058 apl: :Trap exception machinery — Phase 7 complete (+5 tests, 450/450)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m8s
apl-throw raises a tagged ("apl-error" code msg) error.
apl-trap-matches? checks if codes list contains the error's code
(0 = catch-all, à la Dyalog).

Eval-stmt :trap clause wraps try-block with R7RS guard;
on match, runs catch-block; on mismatch, re-raises.
Bonus :throw AST node for testing.

test.sh + conformance.sh now load lib/r7rs.sx (for guard) and
include eval-ops + pipeline suites in scoreboard.

All Phase 7 unchecked items are now ticked.
Final scoreboard: 450/450 across 10 suites.
2026-05-07 14:53:22 +00:00
67ff2a3ae8 apl: idiom corpus 34→64 + fix ≢/≡ glyph recognition (+30 tests, 445/445)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m4s
30 new source-string idioms via apl-run: triangulars, factorial,
running sum/product, parity counts, identity matrix, mult-table,
dot product, ∧.= equality, take/drop/reverse, tally, ravel,
count-of-value, etc.

Side-fix: tokenizer's apl-glyph-set was missing ≢ and ≡ — they
were silently skipped.  Added them and to apl-parse-fn-glyphs.
2026-05-07 14:20:42 +00:00
aaabe370d6 apl: bracket indexing A[I] → (I⌷A) (+7 tests, 415/415)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m29s
Parser: maybe-bracket helper wraps any value followed by [expr]
into (:dyad (:fn-glyph ⌷) idx val).  Wired into :name and :lparen
branches of collect-segments-loop.

apl-run "(10 20 30)[2]" → 20
apl-run "A ← 100 200 300 ⋄ A[2]" → 200
apl-run "(⍳5)[3] × 7" → 21

Multi-axis A[I;J] deferred — needs semicolon-split parsing.
2026-05-07 14:07:05 +00:00
637ba4102f apl: ⎕ quad-names end-to-end (+8 tests, 408/408)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m4s
Parser: apl-quad-fn-names list; is-fn-tok? + :name clause
in collect-segments-loop now route ⎕FMT through fn pipeline.

Eval-ast: :name branch dispatches ⎕IO/⎕ML/⎕FR/⎕TS to apl-quad-*
niladics; apl-monadic-fn handles ⎕FMT.

⎕← (print) deferred — tokenizer splits ⎕← into name + :assign.
2026-05-07 13:49:35 +00:00
7cf8b74d1d apl: end-to-end pipeline apl-run + 25 source-string tests (400/400)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m7s
apl-run = parse-apl + apl-eval-ast against empty env.  Wires
tokenizer + parser + transpile + runtime as one entry point.
test.sh now loads tokenizer.sx + parser.sx alongside transpile.sx.

Source-string tests cover scalars, strands, dyadic arith,
right-to-left precedence, monadic primitives, /, \, ⌈/, ×/,
∘.×, +.×, ⍴, comparisons, classic one-liners.

Tokenizer doesn't yet handle decimal literals (3.7 → 3 . 7),
so two such tests substituted with integer min/max-reduce.
2026-05-07 13:17:39 +00:00
dec1cf3fbe apl: operators in apl-eval-ast via resolvers (+14 tests, 375/375)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m0s
apl-resolve-monadic and apl-resolve-dyadic dispatch :derived-fn,
:outer, and :derived-fn2 nodes to the matching operator helper.
:monad/:dyad in apl-eval-ast now route through these resolvers.

Removed queens(8) test (too slow under current 300s timeout).
2026-05-07 12:45:21 +00:00
d755caeb9a apl: idiom corpus — 34 classic idioms; entire plan complete (362/362)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m2s
2026-05-07 07:29:04 +00:00
3e77dd4ded apl: ⎕ system functions + drive corpus to 100+ (+13 tests, 328/328)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
2026-05-07 06:56:20 +00:00
0f13052900 apl: quicksort recursive partition — Phase 6 classics complete (+9 tests, 315/315)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m0s
2026-05-07 06:23:03 +00:00
e37167a58e apl: n-queens via permute + diagonal filter, q(8)=92 (+10 tests, 306/306)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m5s
2026-05-07 05:46:54 +00:00
49eb22243a apl: mandelbrot real-axis batched z=z²+c (+9 tests, 296/296)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m5s
2026-05-07 05:07:25 +00:00
20a61de693 apl: life Conway via 9-shift toroidal sum (+7 tests, 287/287)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m8s
2026-05-07 04:36:49 +00:00
ed0853f4a0 apl: primes sieve (2=+⌿0=A∘.|A)/A←⍳N + apl-compress (+11 tests, 280/280)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m6s
2026-05-07 04:07:09 +00:00
ec26b61cbe apl: conformance.sh + scoreboard.{json,md} — Phase 5 complete (269/269)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m3s
2026-05-07 03:37:58 +00:00
bee4e0846c apl: niladic/monadic/dyadic valence dispatch (+14 tests, 269/269)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m6s
2026-05-07 03:10:07 +00:00
f591ee17c3 apl: control words :If/:While/:For/:Select (+10 tests, 255/255)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m3s
2026-05-07 02:42:28 +00:00
1900726fc9 apl: tradfn ∇ header — line-numbered stmts + :branch goto (+10 tests, 245/245)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m4s
2026-05-07 02:13:00 +00:00
16167c5d9b apl: dfn complete — guards, locals, ∇ recursion, ⍺← default (+9 tests, 235/235)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m3s
2026-05-07 01:44:19 +00:00
84d210b6b3 apl: dfn foundation — transpile.sx + apl-eval-ast (+15 tests, 226/226)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m2s
2026-05-07 00:57:59 +00:00
4c71c5a75e apl: at @ replace+apply (+10 tests, 211/211)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
2026-05-07 00:27:40 +00:00
9eecbde61e apl: rank f⍤k cell decomposition (+10 tests, 201/201)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m0s
2026-05-07 00:00:14 +00:00
4dbd3a0b34 apl: power f⍣n + fixed-point f⍣≡ (+9 tests, 191/191)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 56s
2026-05-06 23:32:26 +00:00
3d2bdc52b5 apl: compose f∘g (+9 tests, 182/182)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 46s
2026-05-06 23:03:14 +00:00
d570da1dea apl: commute f⍨ (+10 tests, 173/173)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
2026-05-06 22:36:11 +00:00
d67e04a9ad apl: inner product f.g (+12 tests, 163/163)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 58s
2026-05-06 22:09:13 +00:00
4332b4032f apl: outer product ∘.f (+12 tests, 151/151)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
2026-05-06 21:41:15 +00:00
3489c9f131 apl: each f¨ monadic + dyadic (+14 tests, 139/139)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 51s
2026-05-06 21:14:49 +00:00
c56f400403 apl: scan f\ + f⍀ (+15 tests, 125/125)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
2026-05-06 20:46:16 +00:00
c5ceb9c718 apl: reduce f/ and f⌿ (last+first axis); 110/110 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 19:39:11 +00:00
ce72070d2a apl: membership ∊, dyadic ⍳, without ~ (dyadic); 94/94 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 19:24:46 +00:00
e06e3ad014 apl: enclose ⊂ / disclose ⊃; 82/82 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 19:17:30 +00:00
7dfa092ed2 apl: Phase 3 grade-up ⍋ / grade-down ⍒ — 74/74 tests green
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Add apl-grade (stable insertion sort helper), apl-grade-up, apl-grade-down.
Stability guaranteed via secondary sort key (original index). 8 new tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 19:02:49 +00:00
e11fbd6140 apl: Phase 3 squad ⌷ indexing — 66/66 tests green
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Add apl-squad: scalar index into vector, fully-specified multi-dim index,
partial index returning sub-array slice. 7 new tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 18:57:07 +00:00
71ad7d2d24 apl: Phase 3 catenate , and first-axis — 59/59 tests green
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Add apl-catenate (dyadic ,, last-axis join, scalar promotion) and
apl-catenate-first (first-axis join, row-major append). 9 new tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 18:51:32 +00:00
3c83985841 apl: Phase 3 take ↑ / drop ↓ / rotate ⌽⊖ — 50/50 tests green
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Add apl-take (dyadic ↑, multi-axis, cycling pad), apl-drop (dyadic ↓),
apl-reverse (monadic ⌽), apl-rotate (dyadic ⌽, last axis),
apl-reverse-first (monadic ⊖), apl-rotate-first (dyadic ⊖, first axis),
apl-safe-mod helper for negative rotation arithmetic.

23 new tests in lib/apl/tests/structural.sx.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 18:45:12 +00:00
be26f77410 apl: Phase 3 reshape ⍴ / transpose ⍉ — 27/27 structural tests green
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Add apl-reshape (dyadic ⍴, cycling), apl-transpose (monadic ⍉, reverse
axes), apl-transpose-dyadic (dyadic ⍉, permutation), plus helpers
apl-strides / apl-flat->multi / apl-multi->flat.

lib/apl/tests/structural.sx: 27 new tests covering ravel, reshape,
monadic/dyadic transpose across scalar/vector/matrix/3-D cases.

test.sh now runs structural.sx via its own inline framework (skips
stale tests/runtime.sx which targeted a pre-Phase-2 list-based API).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 18:36:43 +00:00
2314735431 apl: merge architecture — Tcl/Prolog/CL/Smalltalk + spec updates
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 18:21:03 +00:00
912de5a274 phase-22 APL: runtime.sx vectors/bitwise/sets/reduce/format
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s
lib/apl/runtime.sx (60 forms):
- Core: apl-iota (1..N), apl-rho (shape), apl-at (1-indexed access).
- Rank-polymorphic apl-dyadic/apl-monadic helpers: scalar×scalar,
  scalar×vector, vector×vector all supported uniformly.
- Arithmetic: add/sub/mul/div/mod/pow/max/min, neg/abs/floor/ceil/sqrt.
- Comparison: eq/neq/lt/le/gt/ge → 0/1 result vectors.
- Boolean: and/or/not on 0/1 values, element-wise.
- Bitwise: bitand/bitor/bitxor/bitnot/lshift/rshift — element-wise.
- Reduction: reduce-add/mul/max/min/and/or; scan-add/mul.
- Vector ops: reverse, cat (scalar/vector catenate), take (±N), drop (±N),
  rotate, compress (boolean mask), index (multi-index).
- Set ops: member (∊, → 0/1), nub (∪, unique preserve-order),
  union, intersect (∩), without (~). All use SX make-set internally.
- Format (⍕): vector → space-separated string, scalar → str.

lib/apl/tests/runtime.sx + lib/apl/test.sh: 73/73 pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 22:49:38 +00:00
4f4b735958 apl: array model + scalar primitives Phase 2 (+82 tests)
Implement lib/apl/runtime.sx — APL array model and scalar primitive library:
- make-array/apl-scalar/apl-vector/enclose/disclose constructors
- array-rank/scalar?/array-ref accessors; apl-io=1 (⎕IO default)
- broadcast-monadic/broadcast-dyadic engine (scalar↔scalar, scalar↔array, array↔array)
- Arithmetic: + - × ÷ ⌈ ⌊ * ⍟ | ! ○ (all monadic+dyadic per APL convention)
- Comparison: < ≤ = ≥ > ≠ (return 0/1)
- Logical: ~ ∧ ∨ ⍱ ⍲
- Shape: ⍴ (apl-shape), , (apl-ravel), ≢ (apl-tally), ≡ (apl-depth)
- ⍳ (apl-iota) with ⎕IO=1 — vector 1..n

82 tests in lib/apl/tests/scalar.sx covering all primitive groups;
includes lists-eq helper for ListRef-aware comparison.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 14:24:49 +00:00
da8ba104a6 apl: right-to-left parser + 44 tests (Phase 1, step 2)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 17s
Implement lib/apl/parser.sx — APL expression parser:
- Segment-based algorithm: scan L→R collecting {fn,val} segments
- build-tree constructs AST with leftmost-fn = root (right-to-left semantics)
- Handles: monadic/dyadic fns, strands (:vec), assignment (:assign)
- Operators: derived-fn (:derived-fn op fn), inner product (:derived-fn2)
- Outer product ∘.f (:outer), dfns {:dfn stmt...}, guards (:guard cond expr)
- split-statements is bracket-aware (depth tracking prevents splitting inside {})

44 new parser tests + 46 existing tokenizer = 90/90 green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 14:05:43 +00:00
c73b696494 apl: tokenizer + 46 tests (Phase 1, step 1)
Unicode-aware byte scanner using starts-with?/consume! for multi-byte
APL glyphs. Handles numbers (¯-negative), string literals, identifiers
(⎕ system names), all APL function/operator glyphs, :Keywords,
comments ⍝, diamond ⋄, assignment ←.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 18:22:30 +00:00