22. Core syntax to 0.3 (2026-11-21)
- 22.1
whereis the 0.3 guard keyword alongsideiffor loops andletconditions.for x in s where c:,[e for x in s where c],if let x = e where c:,while let x = e where c:, and multi-bindingif let a = x, b = y where c:/while let a = x, b = y where c:all parse into the existingCond::Let/Cond::Guard/ filtered-ForAST nodes.for x in s if c:remains accepted so the existing 235 corpus ports stay green without churn. Reversal: remove theat_ident("where")branches incrates/cpl-syntax/src/parser/{stmt,expr}.rs(or deprecatefor ... ifonce ports migrate).
- 22.2 Product array syntax
[(A, B)]Tand table syntax[(A, B)] (a, b) => ...desugar to[A, B]T. Both[(A, B)]T(0.3) and[A, B]T(0.2.2) produce the same flat multi-dimensionalTypeKind::Array, and bothg[(a, b)]andg[a, b]index it, matching 21.1 without breaking existing single-bracket grid diagnostics or ports. Works for domain products ([(R, C)]Int) and counted dimensions ([(n, m)]Int). Reversal: remove the tuple-flattening branch incrates/cpl-syntax/src/parser/{types,expr}.rs.
- 22.3 Optional arithmetic and bitwise lifting covers
+ - * / % ** & | ^ << >>and unary-,~(?T). Previously only+,-, and unary-lifted over?Int/?F64. Per23-optionals.md,+ - * /lift over?Int/?F64,% ** & | ^ << >>and unary~lift over?Int, and ordering (< <= > >=) still does not lift. Implemented via the existingtropicallowering incpl-irand matching rules incpl-check. Reversal: narrow theBinOp/UnOpmatch arms incrates/cpl-check/src/check/expr.rsandcrates/cpl-ir/src/lower/expr.rs.
- 22.4
pairs()andwith_prev()are ordinaryyieldslibrary functions instdlib/seq.cp. Per22-sequences.md,xs.pairs()yields adjacent(prev, x)andxs.with_prev()yields(?T, T)starting with(none, first), with no special loop syntax or compiler privilege. Written asyieldsgenerators overList<T>(which also works on[D]Tarrays via existing coercion) so they fuse into loops in C++ and keepstdlib/prelude.cpat its 80-name cap (imported viause std.seq.{pairs, with_prev}). Reversal: removepairsandwith_prevfromstdlib/seq.cp(or add them tostdlib/prelude.cpif prelude slots open).
- 22.5 One-line colon structs (
struct Edge: to: Int, w: Int) and dotted range-bound types (Self.min..=Self.max).struct_declnow acceptsstruct Name: f1: T1, f2: T2(including shared-typex, y: Intand defaults), producing the sameStructDeclAST node as indented/paren structs.range_followsincpl-syntaxnow skips.identmember chains soSelf.min..=Self.maxandD.first..=D.lastparse asTypeKind::Range. Reversal: remove the one-line colon branch incrates/cpl-syntax/src/parser/item.rsand restore 1-tokenrange_followsincrates/cpl-syntax/src/parser/types.rs.
- 22.6 Range-checked
read::<lo..=hi>()in expression position and homogeneous multi-binding (var a, b, c: Z = (0, 0, 0),let n, m: 1..=20 = read()).read::<lo..=hi>()incpl-irnow lowers aTypeKind::Rangetype argument toSpec::Int { lo, hi, text }, enforcing range bounds identically toread(lo..=hi)andlet x: 1..=3 = read()while keeping::<>turbofish for generic functions. Homogeneous multi-binding (var a, b, c: T = .../let n, m: T = ...) desugars inlet_stmtto a tuple pattern with repeated tuple type(T, T, ...), sovar ones, one_twos, ans: Z = (0, 0, 0)andlet n, m: 1..=20 = read()both work while scalar broadcast (var a, b: Int = 0) remains rejected as a tuple/scalar mismatch. Reversal: remove theTypeKind::Rangebranch incrates/cpl-ir/src/lower/call.rsand removeshared_countincrates/cpl-syntax/src/parser/stmt.rs.
- 22.7 Parenthesized supertraits (
trait Ord(Eq)),&mut Tparameter syntax, opaque structs (struct List<T>), and multi-traitimpl A + B for T.trait_declaccepts(Super1, Super2)alongside: Super1 + Super2;paramdesugarsx: &mut TtoParam { mutable: true, ty: Some(T) }with no new AST node;struct_declallows bodyless opaque declarations (struct List<T>,struct Str);impl_decldesugarsimpl A + B for T:into oneStmtKind::Implper trait. Reversal: revert the four branches incrates/cpl-syntax/src/parser/item.rs.
- 22.8 One-sided range types (
0..,2..,..=8,..n) and associated types intrait/implscope.TypeKind::Rangestoreslo: Option<Box<Expr>>andhi: Option<Box<Expr>>, matching the optional bounds already used bycpl-check::Ty::Rangeandcpl-ir::Spec::Int. Both lower-bounded (0..,2..) and upper-bounded (..n,..=8) ranges now parse, type-check, and emit runtime range checks onread()andread::<2..>().StmtKind::TraitandStmtKind::Implalso bring associatedtype Namedeclarations into their body generic scope sotrait Unwrap: type Out; fn unwrap(self) -> Outchecks cleanly. Reversal: makelo/hinon-optional again inTypeKind::Rangeand remove theTypeAliasloops incrates/cpl-check/src/check/stmt.rs.
- 22.9 Struct type-parameter defaults (
struct Pair<A, B = Int>,struct Graph<V: Index, W = ()>).StructDeclstoresgeneric_defaults: Vec<Option<Type>>andDef::Structstores resolveddefaults: Vec<Option<Ty>>. Omitting trailing type arguments fills them fromdefaults(substituting earlier parameters) in bothcpl-check::def_typeandcpl-ir::instantiate_structbefore memoization, soPair<Int>andPair<Int, Int>are identical types and share one monomorphized struct. Removed theplanned::TYPE_PARAM_DEFAULTstub. Reversal: restoreplanned::TYPE_PARAM_DEFAULTincrates/cpl-syntax/src/planned.rsand removegeneric_defaults/defaults.
- 22.10 Dream ergonomics batch 1: additive const type args (
Mod<1e9 + 7>), multi-clausefor,guard let, and top-levelreturn <unit>. Auditing all 29 dream files (proto/ports/*/dream/*.cp) showed these four forms recurring across 13 dreams:type_argsparses additive value expressions (1e9 + 7,n - 1) asTypeKind::Valuewhen the token after an int/ident/minus is,,>,>>,+,-,*, or**.for_stmtparses comma-separatedpat in iter [where cond]clauses and folds them right-to-left into nestedStmtKind::For.guard let ... else:delegates directly tolet_stmt().StmtKind::Return(Some(e))is accepted at top level (and inUnit-returning fns) whenehas typeUnit(e.g.return print(ans)), lowering toStmt::Expr(e); Stmt::Return(None)while still rejecting non-unit top-level return values. Reversal: revert the four parser/check/IR hunks intypes.rs,stmt.rs,check/stmt.rs, andlower/stmt.rs.
- 22.11 Dream ergonomics batch 2: typed streaming reads
read<[n]T>(),x with field: vrecord update, scalar-fill multi-bindingvar a, b: T = 0, and typed lambda params.names_a_typeincpl-syntaxnow acceptsTypeKind::Range,index_tytreats arithmetic index expressions ([V.count - 1]) as counted arrays0..expr,cpl-fmtrecognizes lowercase generic callsf<...>(...)viacloses_before_lparen, andcpl-irlowers zero-argread<T>()/read::<T>()viaself.resolve(ty, true)+self.read(spec, span)— one general path for ranges, counted arrays, grids, tuples, and structs.ExprKind::With { base, updates }is now lowered incpl-irfor structs and records via aDoblock bindingbaseonce and reconstructing the struct/record tuple with updated fields, removing the E0501withstub.var ones, open, ans: Z = 0andvar ways, next: [1..=m]Z = 0desugar to N separateStmtKind::Letdeclarations when the initializer is not a tuple orread(), while keeping tuple/read destructuring intact.- Lambda parameter lists accept optional
: Typeannotations ((d: Int, l: Low) => ...). This bringsproto/ports/ecnerwala/dream/cf2069c.cp(exemplar #1 indesign/EXEMPLARS-PORTS.md) to 0 errors incpl check, andproto/ports/ecnerwala/cf2069c.cpnow matches its dream exemplar. Reversal: revert the parser/IR/fmt hunks inexpr.rs,types.rs,stmt.rs,call.rs,lower/expr.rs, andspacing.rs.