ludic/fn-len.html
2026-09-17 22:10:03 +00:00

36 lines
No EOL
2.2 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>len — Ludic</title>
<meta name="description" content="The number of elements in a slice, or the byte length of a string.">
<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#builtins">Builtin functions</a> <span>›</span> <span class="here">len</span></div>
<div class="item-head">
<span class="kind-badge kind-builtin">function</span>
<h1 id="top">len</h1>
</div>
<code class="sig">len(x) -&gt; int</code>
<div class="desc"><p>Returns the length of its argument: the element count of a slice, or the byte length of a string. Use it to iterate a slice with <code>for index in 0 .. len(items)</code>, to check whether a collection is empty, or to compute string slice bounds such as trimming a suffix. It reads the current length, so after you <code>push</code> onto a slice the value it returns grows accordingly. For strings, note it counts bytes, not visual characters.</p></div>
<div class="params"><h2>Parameters</h2><div class="param" id="param-x"><code class="pname">x</code><span class="pdesc">a slice or string to measure</span></div></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program CountEnemies {
handler ReportCount phase Start {
let wave_sizes = new []int
push(wave_sizes, 3)
push(wave_sizes, 5)
push(wave_sizes, 8)
print(len(wave_sizes))
}
}</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>