1faee673f7
Boss-dispatched fieldtest after audit-mut-local closed. Six AIL
Surface (.ail) fixtures under examples/fieldtest/ exercise the
shipped mut-local surface from a downstream-LLM-author's perspective
(no compiler-source access; DESIGN.md + public examples only).
Positive fixtures all run end-to-end first-try:
- mut-local_1_factorial.ail: straight-line Int accumulator
unroll (5!), prints 120.
- mut-local_2_classify_temp.ail: nested-if assigns into a Unit-
typed mut block, prints classification code.
- mut-local_3_horner.ail: Float mut accumulator for polynomial
evaluation, prints 18.
- mut-local_4_has_small_factor.ail: Bool mut flag via four
if-then-assign checks, prints true.
Negative probes confirm diagnostics fire as documented:
- mut-local_5_lambda_capture_probe.ail: [mut-var-captured-by-lambda].
- mut-local_6_diag_probe.ail: [mut-var-unsupported-type].
Findings:
[friction] F1 — mut without iteration: the accumulator-over-an-
iteration shape never materializes. Without while/for, the LLM-
author still writes a tail-recursive helper (the very pattern
the milestone Goal said mut would replace). examples/mut_counter.ail
illustrates the degeneration. Routing: planner for a while/for
iteration OR tighten DESIGN.md to name the gap honestly.
[friction] F2 — all four mut-related diagnostics emit their
bracketed [code] twice ('error: [code] fn-name: [code] message').
Mechanical bug: the #[error('[code] ...')] Display attributes I
authored in mut.2/mut.4-tidy include the bracketed prefix in the
message body, and the cli-diag-human formatter adds another from
CheckError::code(). Routing: debug (mechanical message-body
cleanup).
[friction] F3 — no surface form to call a zero-arg fn ('(app f)'
rejected at parse with 'expected at least one argument').
Orthogonal to mut-local but surfaced building the closure-factory
probe. Routing: planner for a small tidy iter.
[spec_gap] F4 — DESIGN.md does not name the 'use a tail-rec
helper instead' workaround for the iteration-over-accumulator
shape that mut alone cannot express. Routing: ratify in DESIGN.md
alongside F1's resolution.
[working] W1/W2/W3 — surface reachable on first read; diagnostics
pinpoint cause (mut-assign-out-of-scope even lists available
vars); composes cleanly with if + lambda-without-capture +
final-expression position.
Spec: docs/specs/2026-05-15-fieldtest-mut-local.md (333 lines).
Refs: docs/specs/2026-05-15-mut-local.md, audit-mut-local close
at 8685e96.
42 lines
1.5 KiB
Plaintext
42 lines
1.5 KiB
Plaintext
; Fieldtest mut-local #2 — classify a temperature into a band using
|
|
; nested if-branches that each update a mut-Int "category code".
|
|
;
|
|
; Task: given a temperature value, set a category-code mut-var to
|
|
; 0 (freezing), 1 (cold), 2 (warm), 3 (hot) by walking through a
|
|
; cascade of if-branches. Print the resulting code.
|
|
;
|
|
; Why this fits mut-local's scope: this exercises mut composed with
|
|
; `if` — each branch contains a single `(assign ...)`. The seal-by-
|
|
; construction promise says the if-branch can write to the var, and
|
|
; the var's value flows out of the branch as the latest store. This is
|
|
; a use of mut that *replaces* what a chain of let-rebinds would
|
|
; otherwise do, and a chain of let-rebinds is the AILang author's
|
|
; usual workaround for "set this variable conditionally" — so the
|
|
; mut form should be measurably cleaner here.
|
|
;
|
|
; Expected stdout: 2 (room temperature 22 = "warm")
|
|
|
|
(module mut-local_2_classify_temp
|
|
|
|
(fn classify
|
|
(doc "Return category code 0..3 for temperature t in degrees C.")
|
|
(type (fn-type (params (con Int)) (ret (con Int))))
|
|
(params t)
|
|
(body
|
|
(mut
|
|
(var code (con Int) 0)
|
|
(if (app < t 0)
|
|
(assign code 0)
|
|
(if (app < t 15)
|
|
(assign code 1)
|
|
(if (app < t 28)
|
|
(assign code 2)
|
|
(assign code 3))))
|
|
code)))
|
|
|
|
(fn main
|
|
(type (fn-type (params) (ret (con Unit)) (effects IO)))
|
|
(params)
|
|
(body
|
|
(app print (app classify 22)))))
|