38 lines
No EOL
2.7 KiB
HTML
38 lines
No EOL
2.7 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>namespace — Ludic</title>
|
||
<meta name="description" content="Group functions into a Name.* namespace and control its public surface.">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="api.html#structure">Program structure</a> <span>›</span> <span class="here">namespace</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-keyword">keyword</span>
|
||
<h1 id="top">namespace</h1>
|
||
</div>
|
||
<code class="sig">namespace Name { export function foo(…) … internal function bar(…) … }</code>
|
||
<div class="desc"><p>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.</p><p>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.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="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
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |