HeadlinesBriefing favicon HeadlinesBriefing.com

New ‘alt’ Syntax Lets Immutability Meet Concise Updates

Hacker News •
×

A developer has released a prototype language that replaces the classic += syntax with a keyword, alt, that applies to all infix operators. The change keeps assignments lexically scoped, letting programmers reason about updates without mutating state.

The language introduces new operators like ]= and .=, mirroring Python’s list assignment and dataclasses.replace. For example, alt l[1][1].age.=9 updates a nested Cat instance to age 9 while preserving the original data structure.

Beyond simple updates, the syntax supports infix binary functions with tildes, enabling concise list extensions such as alt l~push~5. The author envisions a compiler that treats structures as immutable but emits mutable versions when safe, echoing concepts from Swift’s value semantics and Rust’s borrow checker.

This approach offers a clean trade‑off: developers write immutable‑looking code that compiles to efficient mutable operations, potentially improving performance without sacrificing safety.