Error Lab
Every diagnostic below is the real output of ptc, not a mock-up. Pick a mistake, read how the compiler teaches the canonical form, then flip to the fix.
Honest closures
Lambdas capture by value. Mutating a captured copy would silently do nothing to the original — so the compiler refuses and suggests the honest design.
mut seen = [1]
let track = fn(x: Int) -> Void = seen.push(x)The compiler answers
error: 'seen' is captured by value in this lambda — mutating it would only change the lambda's copy; produce the result via the return value instead (line 2, column 34)fn tracked(seen: List[Int], x: Int) -> List[Int]:
mut out = seen
out.push(x)
return out
let seen = tracked([1], 2)
print("{seen}")Fixed — and it runs
[1, 2]