# demo29 — MOLD flag model, loop binding, CONTRAST (2026-11-27)

Build marker: `demo29-2026-11-27`.

## Baseline (all green)

| check | result |
|---|---|
| golden suite, native Linux | **87/87** |
| golden suite, Windows PE under Wine | **87/87** |
| re-bol.com corpus (20 sections) | **325 snippets, 0 errors** (Linux + Wine) |
| examples smoke (7 scripts) | PASS native + Wine |
| net smoke (HTTP/FTP/POP/SMTP/IMAP) | PASS native + Wine |
| ports smoke `--mix` (clone <-> reference) | PASS native + Wine |
| GUI screenshot regression | 3/3, 0.00 % diff |

## 1. MOLD: the break flag lives on the value

The remaining formatted-MOLD gap (VID style objects moulding their inherited
`feel` functions without line breaks) turned out to be a modelling error.
R2 stores the source's line break as a flag on the *value* (plus one flag for
the position before `]`), not as a property of the block.  Probes:

```
mold next load "[1^/2 3]"      -> [\n    2 3\n]      (sub-series keeps it)
mold copy load "[1 2^/]"       -> [1 2]              (copy drops the tail)
mold reduce load "[1 2^/]"     -> [1 2]
mold load "[^/1 2]"            -> [1 2]   while  load "[^/2 2]" -> break kept
b: load "[a^/x]" poke b 2 1    -> [a 1]              (poke clears the flag)
head insert copy [] load "[^/a]" -> [\n    a\n]      (insert carries it)
mold compose [a ([1 2])]       -> [a 1 2]            (compose splices)
```

Implementation (`scan.c`, `native.c`, `eval.c`):

* emit a break before *every* flagged value (first value and sub-series
  included); close on its own line when a break was emitted at that level or
  the tail flag is set;
* `copy`/`reduce`/`compose` no longer propagate the tail flag;
* the shared-integer quirk (`0`/`1` lose the flag) is reproduced in the
  scanner;
* `make object!`/`make function!` deep copies keep the markers, which fixes
  the style objects (`mold select system/view/vid/vid-styles 'scroller` is
  now byte-identical, 627 lines);
* `compose` gained `/deep` and `/only` and now splices block results like R2.

New golden `85-mold-breaks-more` pins all of it.

## 2. Loop variables bind into nested blocks

`repeat`/`foreach`/`for`/`forall`/`forskip`/`remove-each` now bind the loop
word in a temporary context and rebind that name inside the body block
(nested blocks and path heads included).  R2 behaviour verified against the
oracle: the value is visible to `rejoin [i " "]`/`prin rejoin [b/1]` inside a
function, is *not* visible to separately defined functions, and never leaks
to the enclosing context or a same-named global.  `use` rebinds its names the
same way.  New golden `86-loop-binding`.

## 3. DRAW: CONTRAST

`contrast n` was reverse-engineered with 256-level grey ramps and colour
lattices: each channel is stretched around that channel's own *image mean*,

```
mean = sum(channel)/pixels                  (integer, truncated)
out  = mean + trunc((v-mean)*num/den)       (C truncation, clamp 0..255)
num/den = (18+n)/18   (n>=0)   18/(25+|n|)  (n<0)      n clamped to +-128
```

so grey ramps stay grey only when the per-channel means agree; otherwise the
filter adds chroma (which is what had made the earlier probe look like an
unidentified "chroma space").  New golden `87-contrast-effect` pins ten
strengths with an 8-colour image.  `tint` (integer) and `hsv` (tuple) were
probed with the correct argument types and are documented but still
unimplemented: `tint 0` alone perturbs pixels by ±1 (a lossy colour-space
round trip) and `tint n` rotates that space; `hsv h.s.v` maps red to cyan and
grey to white under `0.255.255`.

## 4. TO-IMAGE edge rule

The base face's default edge (`color: 200.200.200 size: 2x2 effect: none`) is
*not* painted by the reference's `to-image`; only bevelled edges (and edge
images) are.  The clone now follows that rule, which fixed the face-effect
goldens once `make face` started producing a real edge object (as R2 does).

## 5. Documentation

`evidence/PORT-MODEL-EVIDENCE.md` §9 records the probes above;
`tests/README.md` documents cases 85–87; `README.md` and this file were
updated for the new counts.
