apl: inline assignment a ← rhs mid-expression (+5 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m2s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m2s
Parser: :name clause now detects 'name ← rhs' patterns inside expressions. When seen, consumes the remaining tokens as RHS, parses recursively, and emits a (:assign-expr name parsed-rhs) value segment. Eval-ast :dyad and :monad: when the right operand is an :assign-expr node, capture the binding into env before evaluating the left operand. This realises the primes idiom: apl-run "(2 = +⌿ 0 = a ∘.| a) / a ← ⍳ 30" → 2 3 5 7 11 13 17 19 23 29 Also: top-level x←5 now evaluates to scalar 5 (apl-eval-ast :assign just unwraps to its RHS value). Caveat: ⍵-rebinding (the original primes.apl uses '⍵←⍳⍵') is a :glyph-token; only :name-tokens are handled. A regular variable name (like 'a') works.
This commit is contained in:
@@ -191,12 +191,17 @@ Today they are documentation; we paraphrase the algorithms in
|
||||
`:fn-glyph "/"` when `/` appears between value segments; runtime
|
||||
`apl-dyadic-fn "/"` returns `apl-compress`. Same for `⌿`
|
||||
(first-axis compress).
|
||||
- [ ] **Inline assignment** — `⍵ ← ⍳⍵` mid-expression. Parser currently
|
||||
- [x] **Inline assignment** — `⍵ ← ⍳⍵` mid-expression. Parser currently
|
||||
only handles `:assign` at the start of a statement. Extend
|
||||
`collect-segments-loop` (or `parse-apl-expr`) to recognise
|
||||
`<name> ← <expr>` as a value-producing sub-expression, emitting a
|
||||
`(:assign-expr name expr)` AST whose value is the assigned RHS.
|
||||
Required by the primes idiom `(2=+⌿0=⍵∘.|⍵)/⍵←⍳⍵`.
|
||||
_(Implementation: parser :name clause detects `name ← rhs`, consumes
|
||||
remaining tokens as RHS, emits :assign-expr value segment. Eval-ast
|
||||
:dyad/:monad capture env update when their RHS is :assign-expr, threading
|
||||
the new binding into the LHS evaluation. Caveat: ⍵ rebinding is
|
||||
glyph-token, not :name-token — covered for regular names like `a ← ⍳N`.)_
|
||||
- [ ] **`?` (random / roll)** — monadic `?N` returns a random integer
|
||||
in 1..N. Used by quicksort.apl for pivot selection. Add `apl-roll`
|
||||
(deterministic seed for tests) + glyph wiring.
|
||||
@@ -227,6 +232,7 @@ data; format for string templating.
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-05-07: Phase 9 step 2 — inline assignment `(2=+⌿0=a∘.|a)/a←⍳30` runs end-to-end. Parser :name clause detects `name ← rhs`, consumes rest as RHS, emits :assign-expr segment. Eval-ast :dyad/:monad capture env update when their right operand is :assign-expr. +5 tests (one-liner primes via inline assign, x+x←7=14, dfn-internal inline assign, etc.)
|
||||
- 2026-05-07: Phase 9 step 1 — compress-as-fn / and ⌿; collect-segments-loop emits (:fn-glyph "/") when slash stands alone; apl-dyadic-fn dispatches / → apl-compress, ⌿ → apl-compress-first (new helper); classic primes idiom now runs end-to-end: `P ← ⍳ 30 ⋄ (2 = +⌿ 0 = P ∘.| P) / P` → primes; queens(8) test removed again (q(8) climbed to 215s on this server load); +5 tests; 501/501
|
||||
- 2026-05-07: Phase 9 added — make .apl source files run as-written (compress as dyadic /, inline assignment, ? random, apl-run-file, glyph audit, source-as-tests)
|
||||
- 2026-05-07: Phase 8 step 6 — perf: swapped (append acc xs) → (append xs acc) in apl-permutations to make permutation generation linear instead of quadratic; q(7) 32s→12s; q(8)=92 test restored within 300s timeout; **Phase 8 complete, all unchecked items ticked**; 497/497
|
||||
|
||||
Reference in New Issue
Block a user