Rename arithmetic operators to named functions (add/sub/mul/div/mod/neg) #27
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal: full surface consistency. Extend the named-function principle
the operator-routing-eq-ord milestone applied to comparison (
==→eq,<→lt, …) to the last special-character builtins. After thismilestone, Form-A contains zero symbol-named identifiers.
Today: arithmetic ops are monomorphic Int builtins, parsed as
operators, desugared to
(app + a b)in Form-A. Form-A is alreadyfunction-application; only the identifier character set is
inconsistent (
eqnext to%).Target Form-A:
+→add-→sub(binary)-(unary) →neg*→mul/→div%→mod(semantics TBD in brainstorm — see below)The same intercept mechanism that ships
eq__Int → icmp eq i64incrates/ailang-codegen/src/lib.rs::try_emit_primitive_instance_bodyapplies directly:
add__Int → add nsw i64,mul__Int → mul nsw i64,etc. No new infrastructure needed.
Prose (Form-B) keeps infix. Per #26, prose renders for human
readability.
(app add a b)in Form-A renders asa + bin prose;the rename is invisible to the prose reader. The prose printer's
rewrite rule extends from
eq → ==to includeadd → +,mul → *,etc.
Surface impact (migration scope):
.ailfixtures underexamples/(currently ~60+ touchingarithmetic)
examples/prelude.aildocs/specs/worked examplesdesign/contracts/examplescrates/ailang-core/src/desugar.rsbuiltin tablescrates/ailang-codegen/src/lib.rsintercept allowlistcrates/ailang-prose/) operator-render tablecrates/ailang-surface/) — may still accept+etc. in Form-A authoring, depending on whether parser strictness is
part of this milestone or a follow-up
Open questions for the brainstorm:
modvsrem— C99%returns sign-of-dividend (rem-semantics);Python
%returns sign-of-divisor (true mod). Pick one and nameit correctly. (Today's
%is C99 rem-semantics; naming itmodwould be a semantic lie.) Probably
remis the honest pick.(app neg x)vs(app sub 0 x). Probably distinctnegto avoid an arithmetic identity in the surface.Numclass(parallel to
Eq/Ord), or stay monomorphic builtins? Affectswhether the milestone touches typechecker class-routing or only
the rename.
(with a warning) for one milestone before they error out, or is
the rename a hard cut at landing?
Trade-off accepted (per user decision 2026-05-21): LLM training
prior favors
+/*/%substantially more than==/<(which theor-milestone already pushed against). Surface consistency wins per
the or-milestone precedent. An LLM that can write
eqcan writeadd.Depends on: none structurally; can ship before or after #26.
Coordinate the prose-printer change with #26's infix-rendering work
so both land in one cohesive prose rewrite.