apl: ⍵-rebind + primes.apl runs as-written (+4 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s
Two changes wire the original primes idiom through:
1. Parser :glyph branch detects ⍵← / ⍺← and emits :assign-expr
(was only :name-token before).
2. Eval-ast :name lookup checks env["⍵"]/env["⍺"] before falling
back to env["omega"]/env["alpha"]. Inline ⍵-rebind binds
under the glyph key directly.
apl-run "primes ← {(2=+⌿0=⍵∘.|⍵)/⍵←⍳⍵} ⋄ primes 50"
→ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
primes.apl now runs as-written via apl-run-file + " ⋄ primes 30".
This commit is contained in:
@@ -344,10 +344,22 @@
|
||||
((= tt :glyph)
|
||||
(cond
|
||||
((or (= tv "⍺") (= tv "⍵"))
|
||||
(collect-segments-loop
|
||||
tokens
|
||||
(+ i 1)
|
||||
(append acc {:kind "val" :node (list :name tv)})))
|
||||
(if
|
||||
(and
|
||||
(< (+ i 1) (len tokens))
|
||||
(= (tok-type (nth tokens (+ i 1))) :assign))
|
||||
(let
|
||||
((rhs-tokens (slice tokens (+ i 2) (len tokens))))
|
||||
(let
|
||||
((rhs-expr (parse-apl-expr rhs-tokens)))
|
||||
(collect-segments-loop
|
||||
tokens
|
||||
(len tokens)
|
||||
(append acc {:kind "val" :node (list :assign-expr tv rhs-expr)}))))
|
||||
(collect-segments-loop
|
||||
tokens
|
||||
(+ i 1)
|
||||
(append acc {:kind "val" :node (list :name tv)}))))
|
||||
((= tv "∇")
|
||||
(collect-segments-loop
|
||||
tokens
|
||||
|
||||
Reference in New Issue
Block a user