Repository conventions
These rules add to the Luna-Flow documentation standard for floating; they
never relax it. The manual describes the implementation on the current branch.
The current version is 0.12.0-pre, the version in library/moon.mod and tooling/moon.mod (a pre-release; the latest published stable release is 0.11.0).
Chapters and guides
Every package has one page per chapter, named after its package path:
- API reference (
api/<package>.md), titled# <package> API, starts with## Purposeand## Importing(themoon.pkgimport and the aliases the examples use), then lists every public item ofpkg.generated.mbtiunder a heading that names it in code, grouped by purpose: the first sentence says what the item does, anmbtiblock gives the signature, and the text states its laws and edge behaviour (errors, flags, NaN, signed zero, overflow), with a smalltestexample for the important items. Closely related items may share one heading. - Tutorial (
tutorial/<package>.md), titled# <package> tutorial, states its goal in the first paragraph, maps tasks to items in an| I want to | Use |table, and continues with## Quick start,## Everyday tasks,## Going further,## Common pitfallsand## Next steps. Its examples are complete and compile. - Design (
design/<package>.md), titled# <package> design, explains the goal, the representation, the mathematics with its derivations, the invariants and the decisions taken, lists the alternatives rejected, and ends with## Boundaries.
The four numerical cores, binary, decimal, decimal_gda and
interval, have two more chapters, as the standard allows:
- Conformance (
conformance/<package>.md) states a pinned, finite evidence claim and its exclusions. - Performance (
performance/<package>.md) records reproducible measurements and target-specific dispatch evidence without making API promises.
The guides are fixed by tools/doc_quality.py: index.md (overview and
package map), getting_started.md (package choice and first steps),
numeric_semantics.md (shared numerical vocabulary), architecture.md
(layers and responsibilities), verification.md (gates and conformance
scope), performance_audit.md (audit of the historical performance baseline)
and this page. Do not add or rename guides without updating that list.
library/README.md positions the current release and points into the manual.
library/CHANGELOG.md owns release history and migration notes.
Package pages
- Mirror every
moon.pkg: the package inlibrary/src/<path>/moon.pkgis documented inapi/<path>.md,tutorial/<path>.mdanddesign/<path>.md. Files do not create packages;moon.pkgboundaries do. - Give every package all three pages. Packages without an application API
(frontends, CLIs,
internal/*,bench/*,consistency,doc_examples) still document their generated interface, maintainer workflow and stability boundary. - Every package also keeps a
library/src/<path>/README.mbt.md. pkg.generated.mbtiis the public-surface inventory; source and tests define behaviour. A method is documented as callable with dot syntax only if the.mbtilists it aspub fn Type::name; trait-implementation methods are not promoted implicitly and must be declared withpub extend.- Do not document planned APIs as existing, and do not keep research notes as
separate pages. Promote durable conclusions into design, conformance or
performance pages, and move superseded history to
library/CHANGELOG.md. - Pages name only the current release. A page may mention an older release
only when it carries a
<!-- historical-performance-baseline: X.Y.Z -->marker for that version;tools/doc_quality.pyrejects any other historical version.
Naming
An operation is named after the standard of its package, in snake_case:
IEEE 754-2019 for binary and decimal and their checked tiers, and the
General Decimal Arithmetic Specification, version 1.70, for decimal_gda and
its checked tier. A package has one spelling per operation: it carries no alias
and never the name of the other standard for the same thing. For example,
decimal names the IEEE remainder as remainder_ctx, and decimal_gda names
the GDA remainder-near as remainder_near.
- Case.
camelCasenames split at each capital (minimumMagnitudeNumberisminimum_magnitude_number) and hyphens become underscores (round-to-integral-exactisround_to_integral_exact). Digits and the standard’s own abbreviations stay attached to their word:exp2m1,log2p1,atan2,sinpi. - Suffixes.
_ctxmarks a method that takes a context and returns the value with its flags.try_marks the form that returns aResultfor a certification failure._checkedand_contextualare the forms of theLuna-Flow/arithmetictraits. The checked tiers (binary_checked,decimal_checked,decimal_gda_checked) keep the bare names. - No standard name. Where the standard has no name for something, such as a
constructor (
from_bigint) or an encoding helper, the spelling with the most uses stays, and the API page documents it. - Documented exceptions. These names are kept as they are, although the
rule would spell them otherwise:
add,sub,mul,div,neg,abs,sqrt,fma;ln,log1p;round,ceil,floor,trunc,to_integral_exact,to_integral_value;sinpiand its family;- the flag name
division_by_zero; parse,to_sci_string,to_eng_string;to_hex,from_hex,to_interchange_hexandfrom_interchange_hex;- in
decimal_gda, alsorescale,applyandtrim(decNumber operations that GDA 1.70 does not define),class_name, and thelogical_prefix.
- Context in
decimal_gda. An operation that takes the context is a free function named after the GDA operation, taking aGdaContextlast and returning aGdaOutcome; a quiet operation that GDA 1.70 says is unaffected by context is a method ofDecimal(copy,copy_sign,same_quantum, theis_*predicates).compare_totalandcompare_total_magnitudeare free functions although the total order itself uses no context: in a subset context (extended=false) the operands are first rounded to the precision (GDA 1.70, Appendix A), which theDecimalmethods of the same names do not do. The design of 0.12 first took them to be context-free and quiet; the 32comparetotalrows of the subset corpusdectest0showed that this holds only in extended contexts. - Kept names with the standard’s term. These names differ from the word of the
standard and are kept on purpose; the API page of each says so:
coefficientandBinCoeff: IEEE 754-2019 2.1 and 3.3 call the component the significand (an integer when the exponent is ), and the standard does not use the word coefficient. The General Decimal Arithmetic Specification does (“coefficient – an integer which is zero or positive”), and one word for the integer view is used in all four packages;- the
*RoundingModetypes: 754-2019 4.3 says rounding-direction attribute; is_signaling_nan,is_quiet_nanandclass_of: 754-2019 5.7.2 has isSignaling andclass(x);DPDandBID: 754-2019 3.5.2 speaks of the decimal encoding and the binary encoding of the significand (a declet is three decimal digits in ten bits, 2.1); the abbreviations are the usual names of the two encodings;normalized: it returns the canonical representation of a value, not the normal number of 754-2019 2.1 (a finite non-zero number of at least the smallest normal magnitude);exponent2andexponent10: the exponent of 754-2019 2.1 is or according to the view of the significand, so the suffix says the radix of the integer power.
- Names of this release that are not the standard’s.
min_numandmax_num(binary,decimal) are the minNum and maxNum of IEEE 754-2008, which 754-2019 replaced by the operations of 9.6 (see the NOTE of 5.3.1); the name says which operation it is.signumis the three-valued classification of the sign of a scalar (Negative,Zero,Positive;Zerofor both zeros and for NaN); the sign of 754-2019 is a bit,is_sign_minus(5.7.2). - Old names. A renamed or removed operation keeps no alias. A name that had
one meaning is not reused with another meaning in the same release. The
release that renames or removes an operation lists the old name and its
replacement under Breaking in
library/CHANGELOG.md.
API snapshots
Every API page ends with ## Complete public interface, whose body is an exact
copy of the package’s pkg.generated.mbti between the markers
<!-- generated-api-start --> and <!-- generated-api-end -->, fenced as
mbti. Individual signatures in the page body are mbti blocks too.
tools/doc_quality.py compares the snapshot with the generated file (it also
accepts the older moonbit fence), so regenerate it whenever moon info
changes the interface.
Numeric documentation rules
- Use
precision,rounding,classify,signum,normalized,exponent,contextandflagsas defined in numeric semantics. - Separate the stored representation, the exact value, the rounded result, status flags, checked errors and interval enclosures.
- State when parsing preserves the exponent and when normalization changes the cohort without changing the value.
- Name the order an API uses.
compare,<and sorting are a total preorder that puts every NaN above every number; the IEEE partial order (with unordered) andtotalOrderare separate APIs. Never imply a scalar order for interval values. - For
*_ctxAPIs, document both the returned value and the flags. - For checked APIs and wrappers, document the domain-specific transition: a result error, IEEE flag accumulation, or a GDA trap short-circuit and its recovery.
- Document
decimalanddecimal_gdaas separate contracts: IEEE operations return per-operation flags, while GDA operations thread sticky status and traps throughGdaOutcome. - Write mathematics in TeX (
$…$,$$…$$) and cite the standard clause or classical result a derivation relies on.
Examples
- Runnable examples are complete top-level items, normally a
testblock, fencedmoonbit, and they show their output withinspect. They must compile and pass against the current branch. - Partial snippets, signatures in prose, executable-package code and
internal/*code that cannot be imported from outside the module, andmoon.pkgsnippets are fencedmoonbit nocheck; shell commands are fencedbash.tools/check_doc_examples.py, run byjust docs, compiles and runs every othermoonbitblock of the manual. - Import aliases:
@lf_algforLuna-Flow/luna-genericand@lf_arithforLuna-Flow/arithmetic; floating packages use their default aliases (@binary,@decimal, …). - Call only what the
.mbtilists. For example,Binaryhas noto_doubleoris_finitemethod; useto_shortest_stringand@def.is_finite(x).
Translations
English pages in doc/manual are the only source. Translations live in the
gettext catalogs doc/locale/<locale>/LC_MESSAGES/manual.po for the locales in
doc/conf.json and are never edited as page copies. Do not translate
identifiers, package names, paths, commands, version strings or mathematics.
Typst attachments live in doc/attachments/ and are shared by all locales.
Review checklist
- Run
moon infoand compare each changedpkg.generated.mbtiwith its API page; refresh the## Complete public interfacesnapshot. - Check that every
moon.pkgstill has itsapi/,tutorial/anddesign/pages (and the evidence pages of the four cores). - Compile and run every changed example (
moonbitblocks) against the current branch. - Run
just docs:tools/doc_quality.py, the manual examples and thetooling/src/doc_examplestests. - Run
lunadoc updateto refreshdoc/locale/manual.potand merge the catalogs, translate new and fuzzy entries, then checklunadoc status(coverage per locale) andlunadoc check --compile(layout, catalogs, links and Typst attachments). - Run
moon fmt,moon check --target all --deny-warn, the relevant tests, andjust prbefore submitting. - On a release bump, update
library/moon.mod, the version inlibrary/README.md, this page andlibrary/CHANGELOG.mdtogether.