ludic/docs/language/structure/kw-namespace.md
Orkuncakilkaya 23e232e380
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 22s
ci / build-and-test (push) Successful in 2m25s
commit-lint / conventional-commits (push) Successful in 5s
docs / build-and-deploy (push) Successful in 29s
feat(lang): #76 namespace block form with export/internal visibility
`namespace Name { export function foo(...) ... internal function bar(...) ... }`
declares a Name.* namespace once and controls its public surface declaratively,
instead of annotating every function with @Namespace(Name). Inside the block
each `function short(...)` is emitted as `namelower_short`; export (the default)
makes it callable as Name.short(...), internal keeps it a private helper
(emitted, callable by short name from siblings — calls are rewritten — but
Name.internalOne() is a compile error). Block sugar for the per-function
@Namespace annotation; a package's public API reads at a glance. Namespaces
declared the old way are unchanged (gameplay_foundation still passes).

namespace added to LUDIC_KW_DECL + JetBrains/TextMate + docs page + inventory
(vocab/impl/docs checks green). Example namespace_block (export + internal +
sibling calls + internal-visibility compile error verified). Full suite 116/0,
fixpoint holds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-02 08:14:54 +03:00

1.5 KiB

id name category kind tokens sig tip order
kw-namespace namespace structure keyword namespace namespace Name { export function foo(…) … internal function bar(…) … } Group functions into a Name.* namespace and control its public surface. 16

A namespace block declares a Name. namespace once and controls its public surface declaratively, instead of annotating every function with @Namespace(Name) one at a time. Inside the block each function short(…) is emitted as namelower_short; an export function (the default) is callable from anywhere as Name.short(…), while an internal function is a private helper — emitted, and callable by its short name from other functions in the same block, but not part of the Name. surface (calling Name.internalOne() is a compile error). It is the block sugar for the per-function @Namespace annotation, so a package's public API reads at a glance.

Sibling calls inside the block use the short name (base()), and the compiler rewrites them to the emitted name — so a namespace reads like a self-contained module.

program Demo {
  namespace Combat {
    export function amount() -> int { return base() + 5 }
    internal function base() -> int { return 10 }
    export function double(n: int) -> int { return n + n }
  }
  entry {
    print(Combat.amount())      # 15
    print(Combat.double(21))    # 42
  }
}