Files
Nim/macrocache.html
github-actions[bot] ef3d9e7b38 Deploy to GitHub pages
2025-12-28 15:55:52 +00:00

562 lines
59 KiB
HTML

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>std/macrocache</title>
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
<!-- JS -->
<script type="text/javascript" src="dochack.js?v=2.3.1"></script>
</head>
<body>
<div class="document" id="documentId">
<div class="container">
<h1 class="title">std/macrocache</h1>
<div class="row">
<div class="three columns">
<div class="theme-select-wrapper">
<label for="theme-select">Theme:&nbsp;</label>
<select id="theme-select" onchange="setTheme(this.value)">
<option value="auto">🌗 Match OS</option>
<option value="dark">🌑 Dark</option>
<option value="light">🌕 Light</option>
</select>
</div>
<div id="global-links">
<ul class="simple-boot">
<li><a href="manual.html">Manual</a></li>
<li><a href="lib.html">Standard library</a></li>
<li> <a id="indexLink" href="theindex.html">Index</a></li>
<li><a href="compiler/theindex.html">Compiler docs</a></li>
<li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
<li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
</ul>
</div>
<div id="searchInputDiv">
Search: <input type="search" id="searchInput"
oninput="search()" />
</div>
<ul class="simple simple-toc" id="toc-list">
<li>
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#CacheCounter" title="CacheCounter = distinct string">CacheCounter</a></li>
<li><a class="reference" href="#CacheSeq" title="CacheSeq = distinct string">CacheSeq</a></li>
<li><a class="reference" href="#CacheTable" title="CacheTable = distinct string">CacheTable</a></li>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">[]
<li><a class="reference" href="#%5B%5D%2CCacheSeq%2CBackwardsIndex" title="`[]`(s: CacheSeq; i: BackwardsIndex): NimNode">`[]`(s: CacheSeq; i: BackwardsIndex): NimNode</a></li>
<li><a class="reference" href="#%5B%5D%2CCacheSeq%2Cint" title="`[]`(s: CacheSeq; i: int): NimNode">`[]`(s: CacheSeq; i: int): NimNode</a></li>
<li><a class="reference" href="#%5B%5D%2CCacheTable%2Cstring" title="`[]`(t: CacheTable; key: string): NimNode">`[]`(t: CacheTable; key: string): NimNode</a></li>
</ul>
<ul class="simple nested-toc-section">[]=
<li><a class="reference" href="#%5B%5D%3D%2CCacheTable%2Cstring%2CNimNode" title="`[]=`(t: CacheTable; key: string; value: NimNode)">`[]=`(t: CacheTable; key: string; value: NimNode)</a></li>
</ul>
<ul class="simple nested-toc-section">add
<li><a class="reference" href="#add%2CCacheSeq%2CNimNode" title="add(s: CacheSeq; value: NimNode)">add(s: CacheSeq; value: NimNode)</a></li>
</ul>
<ul class="simple nested-toc-section">contains
<li><a class="reference" href="#contains%2CCacheTable%2Cstring" title="contains(t: CacheTable; key: string): bool">contains(t: CacheTable; key: string): bool</a></li>
</ul>
<ul class="simple nested-toc-section">hasKey
<li><a class="reference" href="#hasKey%2CCacheTable%2Cstring" title="hasKey(t: CacheTable; key: string): bool">hasKey(t: CacheTable; key: string): bool</a></li>
</ul>
<ul class="simple nested-toc-section">inc
<li><a class="reference" href="#inc%2CCacheCounter%2Cint" title="inc(c: CacheCounter; by = 1)">inc(c: CacheCounter; by = 1)</a></li>
</ul>
<ul class="simple nested-toc-section">incl
<li><a class="reference" href="#incl%2CCacheSeq%2CNimNode" title="incl(s: CacheSeq; value: NimNode)">incl(s: CacheSeq; value: NimNode)</a></li>
</ul>
<ul class="simple nested-toc-section">len
<li><a class="reference" href="#len%2CCacheSeq" title="len(s: CacheSeq): int">len(s: CacheSeq): int</a></li>
<li><a class="reference" href="#len%2CCacheTable" title="len(t: CacheTable): int">len(t: CacheTable): int</a></li>
</ul>
<ul class="simple nested-toc-section">value
<li><a class="reference" href="#value%2CCacheCounter" title="value(c: CacheCounter): int">value(c: CacheCounter): int</a></li>
</ul>
</ul>
</details>
</li>
<li>
<details open>
<summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">items
<li><a class="reference" href="#items.i%2CCacheSeq" title="items(s: CacheSeq): NimNode">items(s: CacheSeq): NimNode</a></li>
</ul>
<ul class="simple nested-toc-section">pairs
<li><a class="reference" href="#pairs.i%2CCacheTable" title="pairs(t: CacheTable): (string, NimNode)">pairs(t: CacheTable): (string, NimNode)</a></li>
</ul>
</ul>
</details>
</li>
</ul>
</div>
<div class="nine columns" id="content">
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
<div id="tocRoot"></div>
<p class="module-desc"><p>This module provides an API for macros to collect compile-time information across module boundaries. It should be used instead of global <tt class="docutils literal"><span class="pre"><span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">compileTime</span><span class="Operator">.</span><span class="Punctuation">}</span></span></tt> variables as those break incremental compilation.</p>
<p>The main feature of this module is that if you create <tt class="docutils literal"><span class="pre"><span class="Identifier">CacheTable</span></span></tt>s or any other <tt class="docutils literal"><span class="pre"><span class="Identifier">Cache</span></span></tt> types with the same name in different modules, their content will be shared, meaning that you can fill a <tt class="docutils literal"><span class="pre"><span class="Identifier">CacheTable</span></span></tt> in one module, and iterate over its contents in another.</p>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macrocache</span>
<span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;myTable&quot;</span>
<span class="Keyword">const</span> <span class="Identifier">mcSeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;mySeq&quot;</span>
<span class="Keyword">const</span> <span class="Identifier">mcCounter</span> <span class="Operator">=</span> <span class="RawData">CacheCounter&quot;myCounter&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Comment"># add new key &quot;val&quot; with the value `myval`</span>
<span class="Keyword">let</span> <span class="Identifier">myval</span> <span class="Operator">=</span> <span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="StringLit">&quot;hello ic&quot;</span><span class="Punctuation">)</span>
<span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;val&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Identifier">myval</span>
<span class="Identifier">assert</span> <span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;val&quot;</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">nnkStrLit</span>
<span class="Comment"># Can access the same cache from different static contexts</span>
<span class="Comment"># All the information is retained</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Comment"># get value from `mcTable` and add it to `mcSeq`</span>
<span class="Identifier">mcSeq</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;val&quot;</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">mcSeq</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">assert</span> <span class="Identifier">mcSeq</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">strVal</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello ic&quot;</span>
<span class="Comment"># increase `mcCounter` by 3</span>
<span class="Identifier">mcCounter</span><span class="Operator">.</span><span class="Identifier">inc</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">mcCounter</span><span class="Operator">.</span><span class="Identifier">value</span> <span class="Operator">==</span> <span class="DecNumber">3</span></pre></p>
<div class="section" id="6">
<h1><a class="toc-backref" href="#6">Imports</a></h1>
<dl class="item">
<a class="reference external" href="assertions.html">assertions</a>
</dl>
</div>
<div class="section" id="7">
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="CacheCounter">
<dt><pre><a href="macrocache.html#CacheCounter"><span class="Identifier">CacheCounter</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
<dd>
Compile-time counter, uses <tt class="docutils literal"><span class="pre"><span class="Identifier">int</span></span></tt> for storing the count.
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L57" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L57" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="CacheSeq">
<dt><pre><a href="macrocache.html#CacheSeq"><span class="Identifier">CacheSeq</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
<dd>
Compile-time sequence of <tt class="docutils literal"><span class="pre"><span class="Identifier">NimNode</span></span></tt>s.
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L51" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L51" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="CacheTable">
<dt><pre><a href="macrocache.html#CacheTable"><span class="Identifier">CacheTable</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <a href="system.html#string"><span class="Identifier">string</span></a></pre></dt>
<dd>
<p>Compile-time table of key-value pairs.</p>
<p>Keys are <tt class="docutils literal"><span class="pre"><span class="Identifier">string</span></span></tt>s and values are <tt class="docutils literal"><span class="pre"><span class="Identifier">NimNode</span></span></tt>s.</p>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L53" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L53" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</dl>
</div>
<div class="section" id="12">
<h1><a class="toc-backref" href="#12">Procs</a></h1>
<dl class="item">
<div id="[]-procs-all">
<div id="[],CacheSeq,BackwardsIndex">
<dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CCacheSeq%2CBackwardsIndex"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="macrocache.html#CacheSeq"><span class="Identifier">CacheSeq</span></a><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#BackwardsIndex"><span class="Identifier">BackwardsIndex</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns the <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>th last value from <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;backTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">mySeq</span> <span class="Operator">&amp;=</span> <span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">42</span><span class="Punctuation">)</span>
<span class="Identifier">mySeq</span> <span class="Operator">&amp;=</span> <span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">7</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">mySeq</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">intVal</span> <span class="Operator">==</span> <span class="DecNumber">7</span> <span class="Comment"># Last item</span>
<span class="Identifier">assert</span> <span class="Identifier">mySeq</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">2</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">intVal</span> <span class="Operator">==</span> <span class="DecNumber">42</span> <span class="Comment"># Second last item</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L133" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L133" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="[],CacheSeq,int">
<dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CCacheSeq%2Cint"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="macrocache.html#CacheSeq"><span class="Identifier">CacheSeq</span></a><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NcsAt&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns the <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>th value from <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;subTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">42</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">mySeq</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">intVal</span> <span class="Operator">==</span> <span class="DecNumber">42</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L123" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L123" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="[],CacheTable,string">
<dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%2CCacheTable%2Cstring"><span class="Identifier">`[]`</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="macrocache.html#CacheTable"><span class="Identifier">CacheTable</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NctGet&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Retrieves the <tt class="docutils literal"><span class="pre"><span class="Identifier">NimNode</span></span></tt> value at <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span><span class="Punctuation">[</span><span class="Identifier">key</span><span class="Punctuation">]</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;subTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;toAdd&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Identifier">newStmtList</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
<span class="Comment"># get the NimNode back</span>
<span class="Identifier">assert</span> <span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;toAdd&quot;</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">nnkStmtList</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L188" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L188" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="[]=-procs-all">
<div id="[]=,CacheTable,string,NimNode">
<dt><pre><span class="Keyword">proc</span> <a href="#%5B%5D%3D%2CCacheTable%2Cstring%2CNimNode"><span class="Identifier">`[]=`</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="macrocache.html#CacheTable"><span class="Identifier">CacheTable</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a><span class="Other">)</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NctPut&quot;</span><span class="Other">,</span>
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Inserts a <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">key</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">)</span></span></tt> pair into <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.<div class="admonition admonition-warning"><span class="admonition-warning-text"><b>Warning:</b></span>
<tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> has to be unique! Assigning <tt class="docutils literal"><span class="pre"><span class="Identifier">value</span></span></tt> to a <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> that is already in the table will result in a compiler error.</div>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;subTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Comment"># assign newLit(5) to the key &quot;value&quot;</span>
<span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;value&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span>
<span class="Comment"># check that we can get the value back</span>
<span class="Identifier">assert</span> <span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;value&quot;</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">nnkIntLit</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L162" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L162" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="add-procs-all">
<div id="add,CacheSeq,NimNode">
<dt><pre><span class="Keyword">proc</span> <a href="#add%2CCacheSeq%2CNimNode"><span class="Identifier">add</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="macrocache.html#CacheSeq"><span class="Identifier">CacheSeq</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a><span class="Other">)</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NcsAdd&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Adds <tt class="docutils literal"><span class="pre"><span class="Identifier">value</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;addTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="StringLit">&quot;hello ic&quot;</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
<span class="Identifier">assert</span> <span class="Identifier">mySeq</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">strVal</span> <span class="Operator">==</span> <span class="StringLit">&quot;hello ic&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L81" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L81" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="contains-procs-all">
<div id="contains,CacheTable,string">
<dt><pre><span class="Keyword">proc</span> <a href="#contains%2CCacheTable%2Cstring"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="macrocache.html#CacheTable"><span class="Identifier">CacheTable</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Alias of <a class="reference internal nimdoc" title="proc hasKey(t: CacheTable; key: string): bool" href="#hasKey,CacheTable,string">hasKey</a> for use with the <tt class="docutils literal"><span class="pre"><span class="Keyword">in</span></span></tt> operator.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;containsEx&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;foo&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Identifier">newEmptyNode</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
<span class="Comment"># Will be true since we gave it a value before</span>
<span class="Identifier">assert</span> <span class="StringLit">&quot;foo&quot;</span> <span class="Keyword">in</span> <span class="Identifier">mcTable</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L215" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L215" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="hasKey-procs-all">
<div id="hasKey,CacheTable,string">
<dt><pre><span class="Keyword">proc</span> <a href="#hasKey%2CCacheTable%2Cstring"><span class="Identifier">hasKey</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="macrocache.html#CacheTable"><span class="Identifier">CacheTable</span></a><span class="Other">;</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">key</span></span></tt> is in the table <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
<p>See also:</p>
<ul class="simple"><li><a class="reference internal nimdoc" title="proc contains(t: CacheTable; key: string): bool" href="#contains,CacheTable,string">contains proc</a> for use with the <tt class="docutils literal"><span class="pre"><span class="Keyword">in</span></span></tt> operator</li>
</ul>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;hasKeyEx&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="Identifier">mcTable</span><span class="Operator">.</span><span class="Identifier">hasKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;foo&quot;</span><span class="Punctuation">)</span>
<span class="Identifier">mcTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;foo&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Identifier">newEmptyNode</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
<span class="Comment"># Will now be true since we inserted a value</span>
<span class="Identifier">assert</span> <span class="Identifier">mcTable</span><span class="Operator">.</span><span class="Identifier">hasKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;foo&quot;</span><span class="Punctuation">)</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L200" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L200" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="inc-procs-all">
<div id="inc,CacheCounter,int">
<dt><pre><span class="Keyword">proc</span> <a href="#inc%2CCacheCounter%2Cint"><span class="Identifier">inc</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="macrocache.html#CacheCounter"><span class="Identifier">CacheCounter</span></a><span class="Other">;</span> <span class="Identifier">by</span> <span class="Other">=</span> <span class="DecNumber">1</span><span class="Other">)</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NccInc&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Increments the counter <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt> with the value <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Keyword">let</span> <span class="Identifier">counter</span> <span class="Operator">=</span> <span class="RawData">CacheCounter&quot;incTest&quot;</span>
<span class="Identifier">inc</span> <span class="Identifier">counter</span>
<span class="Identifier">inc</span> <span class="Identifier">counter</span><span class="Punctuation">,</span> <span class="DecNumber">5</span>
<span class="Identifier">assert</span> <span class="Identifier">counter</span><span class="Operator">.</span><span class="Identifier">value</span> <span class="Operator">==</span> <span class="DecNumber">6</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L71" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L71" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="incl-procs-all">
<div id="incl,CacheSeq,NimNode">
<dt><pre><span class="Keyword">proc</span> <a href="#incl%2CCacheSeq%2CNimNode"><span class="Identifier">incl</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="macrocache.html#CacheSeq"><span class="Identifier">CacheSeq</span></a><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a><span class="Other">)</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NcsIncl&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Adds <tt class="docutils literal"><span class="pre"><span class="Identifier">value</span></span></tt> to <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Hint:</b></span>
This doesn't do anything if <tt class="docutils literal"><span class="pre"><span class="Identifier">value</span></span></tt> is already in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.</div>
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;inclTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">incl</span><span class="Punctuation">(</span><span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Comment"># still one element</span>
<span class="Identifier">assert</span> <span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L94" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L94" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="len-procs-all">
<div id="len,CacheSeq">
<dt><pre><span class="Keyword">proc</span> <a href="#len%2CCacheSeq"><span class="Identifier">len</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="macrocache.html#CacheSeq"><span class="Identifier">CacheSeq</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NcsLen&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns the length of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;lenTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Keyword">let</span> <span class="Identifier">val</span> <span class="Operator">=</span> <span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="StringLit">&quot;helper&quot;</span><span class="Punctuation">)</span>
<span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">val</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
<span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">val</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">mySeq</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">2</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L109" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L109" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
<div id="len,CacheTable">
<dt><pre><span class="Keyword">proc</span> <a href="#len%2CCacheTable"><span class="Identifier">len</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="macrocache.html#CacheTable"><span class="Identifier">CacheTable</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NctLen&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns the number of elements in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">dataTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;lenTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">dataTable</span><span class="Punctuation">[</span><span class="StringLit">&quot;key&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span>
<span class="Identifier">assert</span> <span class="Identifier">dataTable</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L178" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L178" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="value-procs-all">
<div id="value,CacheCounter">
<dt><pre><span class="Keyword">proc</span> <a href="#value%2CCacheCounter"><span class="Identifier">value</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="macrocache.html#CacheCounter"><span class="Identifier">CacheCounter</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;NccValue&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns the value of a counter <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Keyword">let</span> <span class="Identifier">counter</span> <span class="Operator">=</span> <span class="RawData">CacheCounter&quot;valTest&quot;</span>
<span class="Comment"># default value is 0</span>
<span class="Identifier">assert</span> <span class="Identifier">counter</span><span class="Operator">.</span><span class="Identifier">value</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
<span class="Identifier">inc</span> <span class="Identifier">counter</span>
<span class="Identifier">assert</span> <span class="Identifier">counter</span><span class="Operator">.</span><span class="Identifier">value</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L60" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L60" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
</dl>
</div>
<div class="section" id="15">
<h1><a class="toc-backref" href="#15">Iterators</a></h1>
<dl class="item">
<div id="items-iterators-all">
<div id="items.i,CacheSeq">
<dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2CCacheSeq"><span class="Identifier">items</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="macrocache.html#CacheSeq"><span class="Identifier">CacheSeq</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Iterates over each item in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">myseq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;itemsTest&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">myseq</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Identifier">myseq</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">42</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
<span class="Keyword">for</span> <span class="Identifier">val</span> <span class="Keyword">in</span> <span class="Identifier">myseq</span><span class="Punctuation">:</span>
<span class="Comment"># check that all values in `myseq` are int literals</span>
<span class="Identifier">assert</span> <span class="Identifier">val</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">nnkIntLit</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L146" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L146" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
<div id="pairs-iterators-all">
<div id="pairs.i,CacheTable">
<dt><pre><span class="Keyword">iterator</span> <a href="#pairs.i%2CCacheTable"><span class="Identifier">pairs</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="macrocache.html#CacheTable"><span class="Identifier">CacheTable</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Iterates over all <tt class="docutils literal"><span class="pre"><span class="Punctuation">(</span><span class="Identifier">key</span><span class="Punctuation">,</span> <span class="Identifier">value</span><span class="Punctuation">)</span></span></tt> pairs in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.
<p><strong class="examples_text">Example:</strong></p>
<pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
<span class="Keyword">const</span> <span class="Identifier">mytabl</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;values&quot;</span>
<span class="Keyword">static</span><span class="Punctuation">:</span>
<span class="Identifier">mytabl</span><span class="Punctuation">[</span><span class="StringLit">&quot;intVal&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">5</span><span class="Punctuation">)</span>
<span class="Identifier">mytabl</span><span class="Punctuation">[</span><span class="StringLit">&quot;otherVal&quot;</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Identifier">newLit</span><span class="Punctuation">(</span><span class="DecNumber">6</span><span class="Punctuation">)</span>
<span class="Keyword">for</span> <span class="Identifier">key</span><span class="Punctuation">,</span> <span class="Identifier">val</span> <span class="Keyword">in</span> <span class="Identifier">mytabl</span><span class="Punctuation">:</span>
<span class="Comment"># make sure that we actually get the same keys</span>
<span class="Identifier">assert</span> <span class="Identifier">key</span> <span class="Keyword">in</span> <span class="Punctuation">[</span><span class="StringLit">&quot;intVal&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;otherVal&quot;</span><span class="Punctuation">]</span>
<span class="Comment"># all vals are int literals</span>
<span class="Identifier">assert</span> <span class="Identifier">val</span><span class="Operator">.</span><span class="Identifier">kind</span> <span class="Operator">==</span> <span class="Identifier">nnkIntLit</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L229" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L229" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
</dl>
</div>
</div>
</div>
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br>
<small style="color: var(--hint);">Made with Nim. Generated: 2025-12-28 15:55:28 UTC</small>
</div>
</div>
</div>
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
</body>
</html>