; 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)))))