43 lines
No EOL
2.4 KiB
HTML
43 lines
No EOL
2.4 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>let — Ludic</title>
|
||
<meta name="description" content="An immutable binding — the default choice for a value that never changes.">
|
||
<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">let</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-keyword">keyword</span>
|
||
<h1 id="top">let</h1>
|
||
</div>
|
||
<code class="sig">let name = value</code>
|
||
<div class="desc"><p>A <code>let</code> introduces an <b>immutable</b> binding: once set, reassigning it (<code>name = …</code>) is a compile error. Reach for <code>let</code> by default and only switch to <code>var</code> when a value genuinely needs to change — it makes intent obvious and catches accidental writes. Immutability is of the <b>binding</b>, not the object it points at: a <code>let</code> that holds a property record or a slice still lets you mutate through it (<code>node.current = 5</code>), it just cannot be repointed at a different object. Bindings inside a body are locals scoped to their block.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Damage {
|
||
property Health { current: int = 100, maximum: int = 100 }
|
||
model Enemy { Health }
|
||
|
||
handler Boot phase Start {
|
||
spawn Grunt { Health { current: 40 } }
|
||
}
|
||
|
||
handler ApplyHit phase Update {
|
||
let incoming_damage = 12
|
||
for (health) in query [Health, {Enemy}] {
|
||
let survivor = health.current - incoming_damage
|
||
health.current = survivor
|
||
}
|
||
}
|
||
}</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> |