13. Leaning since 2026-11-20: scout batch 1
The first scout batch (research/archive/frictions/friction-backlog.md) re-solved ten
corpus problems and listed what the prototype made awkward. The changes
below are implemented in proto/cpc/, eight of the ten sketches now pass
against their originals as ports, and crates/cpl-cli/tests/cases/ergo/ and
crates/cpl-cli/tests/cases/bad/ lock them. None is confirmed by Ryan yet, so each is
Leaning, and each says what is library code and what is not.
-
A compound assignment on a missing map key starts from the identity of its operation. A rule, and a bug fix:
m[k] min= xon a key that was not there started from 0. Nowm[k] f= xon a missing key storesf(id, x), whereidis the identity offinstd.algebra: 0 for+,-,|,^andgcd, 1 for*andlcm.minandmaxhave no identity overInt, so they storex, the same "insert if none" thatmin=on a?Intalready had. An operation with no known identity is a compile error that asks what a missing key means:m[d] min= hops // first write stores hops m[d] /= 2 // error: `/` has no identity to start it from m[d] = (m.get(d) ?? 1) / 2 // what the error suggestsThis is the monoid rule the library already uses (
optof a semigroup), applied to one place, not a special case formin. -
e?works inside an expression. Syntax, widening 4.1:?was only allowed on a wholelet. Nowi.ord + on_foot[line[i]]?leaves the fn withnonewhen the operand isnone. The operands before it are still evaluated first, left to right. Inside a branch, a lambda or a comprehension it stays an error for now, because "leave the fn" from there is not obvious to a reader. -
let a = x and let b = y else:andlet (a, b) = (x, y) else:. Syntax. The sameandchainif letalready has, on the early-exit form, so two optional steps need neither nesting nor a secondelse. -
minandmaxskipnone. Typing: with every argument aTthe result is aTas before; with some?Tthenones are skipped, and the result is aTwhen at least one argument is a plainT, a?Totherwise. It is theoptmonoid again:noneis the identity. -
.fieldis the fnx => x.field. Syntax, only where a one-argument fn is expected:sorted(links, by: .cost),Rooted(roads, root, weight: .len). -
An operator names its two-argument fn. Syntax, only as a call argument:
scan(a, +),SegTree<V, Int>.of(+, f). With itx f= y,scan(a, f)and.of(f, ...)all take the same thing, an operator or a named fn. -
[k: v, ...]is a map literal and[n - 1]Ttakes anyIntexpression as a count. Syntax; both were parse errors. -
A read range is the range that was written, inside records too. Section 12 made
let k: 1..=n = read()check and generate against the valuenhas. The same now holds for a range that is a field or an element:let friends: [n](x: l..=r, v: 1..=100) = read(). -
read(columns). Library: an array of records is read one field at a time (all the outcomes, then all the points) instead of one record at a time. The data keeps the shape the solution wants; only the input order differs. -
An enum whose
@tagsare single characters reads packed.@tags("W", "L")readsWLWWas four values, the wayCharalready does. Library (readfor such an enum). -
use std.module.{Name}in a port. The prototype compiler still cannot compile the library's own.cp(that needs structs with methods and generics incpc), so it compiles in a stand-in for each name, as it already did forSegTree. Theuseis checked against the real module: the name must bepubinstdlib/module.cp. The new stand-ins arebfs,choose,Steps,scanandrunning_sum, and using one of them without itsuseis an error. Each has the same name, arguments and meaning as the.cpdefinition, whichproto/cp.py test stdlibruns on the interpreter. The stand-ins that were there before (SegTree,Rooted,Dsu,Graph,scc) still work without ause, because the existing ports use them that way; a port may import them, andDsu<V>.new()and.countare accepted as the library spells them. -
Library additions. All plain library code in
stdlib/:choose(n, k)instd.math;scan(xs, f)andrunning_sum(xs)in the newstd.seq;Stepsin the newstd.steps(add(range, x), thenruns(clip)gives the maximal runs of equal value, which is the sorted-events sweep);SegTree.of(m, f)withrefresh(i)and.all, so a tree over a formula states the formula once;Rooted.weightedand adistthat adds edge lengths (it still counts edges when none are given). In the prototype compiler only:Set(xs),take(place),a.swap(i, j)(plan/19 §4.5),D.windows(k),first_whereon any range,pre.sum(from: v, len: k)wrapping around the domain,prefixover aBoolarray or fn (it counts), and on theRootedstand-in of section 12weight:, withtree.kidsandtree.rootas the library names them.
Two things were looked at and not done. m[k] f= x could have required
an explicit start value for every operation; that makes the common
m[k] += 1 longer to protect the rare m[k] /= x, so only the
operations without an identity ask. And ? could have been allowed
everywhere; see above.