`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>
28 lines
1.5 KiB
Markdown
28 lines
1.5 KiB
Markdown
---
|
|
id: kw-namespace
|
|
name: namespace
|
|
category: structure
|
|
kind: keyword
|
|
tokens: namespace
|
|
sig: namespace Name { export function foo(…) … internal function bar(…) … }
|
|
tip: Group functions into a Name.* namespace and control its public surface.
|
|
order: 16
|
|
---
|
|
|
|
A <code>namespace</code> block declares a <code>Name.*</code> namespace once and controls its public surface declaratively, instead of annotating every function with <code>@Namespace(Name)</code> one at a time. Inside the block each <code>function short(…)</code> is emitted as <code>namelower_short</code>; an <code>export</code> function (the default) is callable from anywhere as <code>Name.short(…)</code>, while an <code>internal</code> function is a private helper — emitted, and callable by its short name from other functions in the same block, but not part of the <code>Name.*</code> surface (calling <code>Name.internalOne()</code> is a compile error). It is the block sugar for the per-function <code>@Namespace</code> annotation, so a package's public API reads at a glance.
|
|
|
|
Sibling calls inside the block use the short name (<code>base()</code>), and the compiler rewrites them to the emitted name — so a namespace reads like a self-contained module.
|
|
|
|
```ludic
|
|
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
|
|
}
|
|
}
|
|
```
|