ludic/docs/language/annotations/annot-namespace.md
Orkuncakilkaya 6c6dfae235
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 20s
ci / build-and-test (push) Successful in 1m41s
commit-lint / conventional-commits (push) Successful in 3s
docs / build-and-deploy (push) Successful in 27s
docs(pkg): document @Namespace / @EngineSystem / @System + package hooks (#62)
Per-annotation pages for the three package-registration annotations (with
inventory entries), a "Package-declarable namespaces and engine systems" section
in docs/PACKAGES.md, and a changeset. All doc gates green (check-docs 675
fences, docs-check 726 symbols).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-01 12:31:47 +03:00

1.4 KiB


id: annot-namespace name: @Namespace category: annotations kind: annotation tokens: @Namespace sig: "@Namespace(Name) function name_method(…) -> T { … }" tip: Let a package provide a Name.method(…) namespace that dispatches to name_method. order: 61

@Namespace(Name) registers Name as a namespace a package provides, so a caller can write Name.method(…) and the compiler dispatches it to the bare function name_method(…) (the namespace lowercased, an underscore, then the method). It is the package-declarable form of the built-in Foo. stdlib namespaces (Regex., Grid.*, …): a third-party package ships the same call shape without editing the compiler. The alias goes through the same generic call path the core namespaces use and preserves the target function's return type; it only applies after every built-in namespace, so it never shadows a core one. Mark each function that backs a method (the registration is idempotent — one mark is enough to open the namespace, but marking each provider documents the surface).

program NamespaceDemo {
  @Namespace(Coach) function coach_bonus() -> int { return 99 }
  @Namespace(Coach) function coach_double(n: int) -> int { return n + n }

  entry {
    print(Coach.bonus())        # 99  — dispatches to coach_bonus
    print(Coach.double(21))     # 42  — dispatches to coach_double
  }
}