Files
AILang/examples/fieldtest/loop_recur_4_gcd_value_pos.ail
T
Brummel 2ed355c6fa fieldtest: loop-recur — 10 examples, 6 findings (milestone CLOSE, clean on all axes)
Post-audit downstream-LLM-author field test of the shipped
loop/recur surface (DESIGN.md + public examples only). 3 real
iterative programs (Newton isqrt, Collatz, Euclidean gcd) + 5
plausible-mistake negatives + 2 no-termination probes, all run
through the public ail CLI. 0 bugs. 4 working findings on the
milestone's own axes: rejection diagnostics point-exact AND
self-fixing; recur tail-position threads through match/let/outer-if
(spec only showed if); loop composes as a value sub-expression +
byte-stable round-trip; no-termination boundary exact. This
empirically substantiates the "LLM author can now write iterative
programs" claim.

Two orthogonal non-blocking findings, neither in loop/recur scope,
both routed to P2 todos (refused the scope creep into a loop/recur
tidy): niladic (app f) spec_gap independently re-confirms the
existing mut-local-F3 roadmap item (the design-fork decision
deliberately NOT auto-ratified under /boss — parked,
priority-strengthened); module-level (doc) diagnostic-hint friction
(one-line tidy). Boss-verified independently (gcd->27;
recur-outside-loop fires exact).

The standalone loop/recur milestone is fully ratified and CLOSED:
3 iterations + tidy shipped, audit clean (drift resolved, bench
pristine carry-on), fieldtest clean on every axis. Roadmap P0
marked closed.
2026-05-18 00:31:19 +02:00

25 lines
1.0 KiB
Plaintext

; Two things at once:
; (1) `loop` used as a sub-expression in argument position — the
; (loop ...) result of `gcd` is passed straight into another
; call (`app print (app + (app gcd 48 18) (app gcd 1071 462)))`),
; not used as a whole fn body. Expected stdout: 27 (gcd(48,18)=6
; plus gcd(1071,462)=21).
; (2) Euclid's algorithm is a textbook real iterative algorithm an
; LLM author reaches for `loop`/`recur` to write; single-binder
; pair? no — two binders (a, b), recur swaps/reduces.
(module loop_recur_4_gcd_value_pos
(fn gcd
(doc "Euclidean gcd via loop/recur. Two binders a,b; recur in the tail of the else branch.")
(type (fn-type (params (con Int) (con Int)) (ret (con Int))))
(params x y)
(body
(loop (a (con Int) x) (b (con Int) y)
(if (app == b 0)
a
(recur b (app % a b))))))
(fn main
(type (fn-type (params) (ret (con Unit)) (effects IO)))
(params)
(body
(app print (app + (app gcd 48 18) (app gcd 1071 462))))))