macrocache.html 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/macrocache</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <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=="/>
  14. <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=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/macrocache</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li>
  50. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  51. </li>
  52. <li>
  53. <details open>
  54. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  55. <ul class="simple simple-toc-section">
  56. <li><a class="reference" href="#CacheCounter" title="CacheCounter = distinct string">CacheCounter</a></li>
  57. <li><a class="reference" href="#CacheSeq" title="CacheSeq = distinct string">CacheSeq</a></li>
  58. <li><a class="reference" href="#CacheTable" title="CacheTable = distinct string">CacheTable</a></li>
  59. </ul>
  60. </details>
  61. </li>
  62. <li>
  63. <details open>
  64. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  65. <ul class="simple simple-toc-section">
  66. <ul class="simple nested-toc-section">[]
  67. <li><a class="reference" href="#%5B%5D%2CCacheSeq%2CBackwardsIndex" title="`[]`(s: CacheSeq; i: BackwardsIndex): NimNode">`[]`(s: CacheSeq; i: BackwardsIndex): NimNode</a></li>
  68. <li><a class="reference" href="#%5B%5D%2CCacheSeq%2Cint" title="`[]`(s: CacheSeq; i: int): NimNode">`[]`(s: CacheSeq; i: int): NimNode</a></li>
  69. <li><a class="reference" href="#%5B%5D%2CCacheTable%2Cstring" title="`[]`(t: CacheTable; key: string): NimNode">`[]`(t: CacheTable; key: string): NimNode</a></li>
  70. </ul>
  71. <ul class="simple nested-toc-section">[]=
  72. <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>
  73. </ul>
  74. <ul class="simple nested-toc-section">add
  75. <li><a class="reference" href="#add%2CCacheSeq%2CNimNode" title="add(s: CacheSeq; value: NimNode)">add(s: CacheSeq; value: NimNode)</a></li>
  76. </ul>
  77. <ul class="simple nested-toc-section">contains
  78. <li><a class="reference" href="#contains%2CCacheTable%2Cstring" title="contains(t: CacheTable; key: string): bool">contains(t: CacheTable; key: string): bool</a></li>
  79. </ul>
  80. <ul class="simple nested-toc-section">hasKey
  81. <li><a class="reference" href="#hasKey%2CCacheTable%2Cstring" title="hasKey(t: CacheTable; key: string): bool">hasKey(t: CacheTable; key: string): bool</a></li>
  82. </ul>
  83. <ul class="simple nested-toc-section">inc
  84. <li><a class="reference" href="#inc%2CCacheCounter%2Cint" title="inc(c: CacheCounter; by = 1)">inc(c: CacheCounter; by = 1)</a></li>
  85. </ul>
  86. <ul class="simple nested-toc-section">incl
  87. <li><a class="reference" href="#incl%2CCacheSeq%2CNimNode" title="incl(s: CacheSeq; value: NimNode)">incl(s: CacheSeq; value: NimNode)</a></li>
  88. </ul>
  89. <ul class="simple nested-toc-section">len
  90. <li><a class="reference" href="#len%2CCacheSeq" title="len(s: CacheSeq): int">len(s: CacheSeq): int</a></li>
  91. <li><a class="reference" href="#len%2CCacheTable" title="len(t: CacheTable): int">len(t: CacheTable): int</a></li>
  92. </ul>
  93. <ul class="simple nested-toc-section">value
  94. <li><a class="reference" href="#value%2CCacheCounter" title="value(c: CacheCounter): int">value(c: CacheCounter): int</a></li>
  95. </ul>
  96. </ul>
  97. </details>
  98. </li>
  99. <li>
  100. <details open>
  101. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  102. <ul class="simple simple-toc-section">
  103. <ul class="simple nested-toc-section">items
  104. <li><a class="reference" href="#items.i%2CCacheSeq" title="items(s: CacheSeq): NimNode">items(s: CacheSeq): NimNode</a></li>
  105. </ul>
  106. <ul class="simple nested-toc-section">pairs
  107. <li><a class="reference" href="#pairs.i%2CCacheTable" title="pairs(t: CacheTable): (string, NimNode)">pairs(t: CacheTable): (string, NimNode)</a></li>
  108. </ul>
  109. </ul>
  110. </details>
  111. </li>
  112. </ul>
  113. </div>
  114. <div class="nine columns" id="content">
  115. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  116. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  117. <div id="tocRoot"></div>
  118. <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>
  119. <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>
  120. <p><strong class="examples_text">Example:</strong></p>
  121. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macrocache</span>
  122. <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  123. <span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;myTable&quot;</span>
  124. <span class="Keyword">const</span> <span class="Identifier">mcSeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;mySeq&quot;</span>
  125. <span class="Keyword">const</span> <span class="Identifier">mcCounter</span> <span class="Operator">=</span> <span class="RawData">CacheCounter&quot;myCounter&quot;</span>
  126. <span class="Keyword">static</span><span class="Punctuation">:</span>
  127. <span class="Comment"># add new key &quot;val&quot; with the value `myval`</span>
  128. <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>
  129. <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>
  130. <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>
  131. <span class="Comment"># Can access the same cache from different static contexts</span>
  132. <span class="Comment"># All the information is retained</span>
  133. <span class="Keyword">static</span><span class="Punctuation">:</span>
  134. <span class="Comment"># get value from `mcTable` and add it to `mcSeq`</span>
  135. <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>
  136. <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>
  137. <span class="Keyword">static</span><span class="Punctuation">:</span>
  138. <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>
  139. <span class="Comment"># increase `mcCounter` by 3</span>
  140. <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>
  141. <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>
  142. <div class="section" id="6">
  143. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  144. <dl class="item">
  145. <a class="reference external" href="assertions.html">assertions</a>
  146. </dl>
  147. </div>
  148. <div class="section" id="7">
  149. <h1><a class="toc-backref" href="#7">Types</a></h1>
  150. <dl class="item">
  151. <div id="CacheCounter">
  152. <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>
  153. <dd>
  154. Compile-time counter, uses <tt class="docutils literal"><span class="pre"><span class="Identifier">int</span></span></tt> for storing the count.
  155. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L57" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  156. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L57" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  157. </dd>
  158. </div>
  159. <div id="CacheSeq">
  160. <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>
  161. <dd>
  162. Compile-time sequence of <tt class="docutils literal"><span class="pre"><span class="Identifier">NimNode</span></span></tt>s.
  163. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L51" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  164. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L51" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  165. </dd>
  166. </div>
  167. <div id="CacheTable">
  168. <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>
  169. <dd>
  170. <p>Compile-time table of key-value pairs.</p>
  171. <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>
  172. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L53" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  173. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L53" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  174. </dd>
  175. </div>
  176. </dl>
  177. </div>
  178. <div class="section" id="12">
  179. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  180. <dl class="item">
  181. <div id="[]-procs-all">
  182. <div id="[],CacheSeq,BackwardsIndex">
  183. <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>
  184. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  185. <dd>
  186. 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>.
  187. <p><strong class="examples_text">Example:</strong></p>
  188. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  189. <span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;backTest&quot;</span>
  190. <span class="Keyword">static</span><span class="Punctuation">:</span>
  191. <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>
  192. <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>
  193. <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>
  194. <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>
  195. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L133" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  196. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L133" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  197. </dd>
  198. </div>
  199. <div id="[],CacheSeq,int">
  200. <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>
  201. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  202. <dd>
  203. 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>.
  204. <p><strong class="examples_text">Example:</strong></p>
  205. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  206. <span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;subTest&quot;</span>
  207. <span class="Keyword">static</span><span class="Punctuation">:</span>
  208. <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>
  209. <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>
  210. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L123" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  211. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L123" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  212. </dd>
  213. </div>
  214. <div id="[],CacheTable,string">
  215. <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>
  216. <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>
  217. <dd>
  218. 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>.
  219. <p><strong class="examples_text">Example:</strong></p>
  220. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  221. <span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;subTest&quot;</span>
  222. <span class="Keyword">static</span><span class="Punctuation">:</span>
  223. <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>
  224. <span class="Comment"># get the NimNode back</span>
  225. <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>
  226. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L188" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  227. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L188" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  228. </dd>
  229. </div>
  230. </div>
  231. <div id="[]=-procs-all">
  232. <div id="[]=,CacheTable,string,NimNode">
  233. <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>
  234. <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>
  235. <dd>
  236. 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>
  237. <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>
  238. <p><strong class="examples_text">Example:</strong></p>
  239. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  240. <span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;subTest&quot;</span>
  241. <span class="Keyword">static</span><span class="Punctuation">:</span>
  242. <span class="Comment"># assign newLit(5) to the key &quot;value&quot;</span>
  243. <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>
  244. <span class="Comment"># check that we can get the value back</span>
  245. <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>
  246. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L162" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  247. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L162" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  248. </dd>
  249. </div>
  250. </div>
  251. <div id="add-procs-all">
  252. <div id="add,CacheSeq,NimNode">
  253. <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>
  254. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  255. <dd>
  256. 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>.
  257. <p><strong class="examples_text">Example:</strong></p>
  258. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  259. <span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;addTest&quot;</span>
  260. <span class="Keyword">static</span><span class="Punctuation">:</span>
  261. <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>
  262. <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>
  263. <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>
  264. <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>
  265. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L81" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  266. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L81" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  267. </dd>
  268. </div>
  269. </div>
  270. <div id="contains-procs-all">
  271. <div id="contains,CacheTable,string">
  272. <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>
  273. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  274. <dd>
  275. 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.
  276. <p><strong class="examples_text">Example:</strong></p>
  277. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  278. <span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;containsEx&quot;</span>
  279. <span class="Keyword">static</span><span class="Punctuation">:</span>
  280. <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>
  281. <span class="Comment"># Will be true since we gave it a value before</span>
  282. <span class="Identifier">assert</span> <span class="StringLit">&quot;foo&quot;</span> <span class="Keyword">in</span> <span class="Identifier">mcTable</span></pre>
  283. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L215" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  284. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L215" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  285. </dd>
  286. </div>
  287. </div>
  288. <div id="hasKey-procs-all">
  289. <div id="hasKey,CacheTable,string">
  290. <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>
  291. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  292. <dd>
  293. <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>
  294. <p>See also:</p>
  295. <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>
  296. </ul>
  297. <p><strong class="examples_text">Example:</strong></p>
  298. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  299. <span class="Keyword">const</span> <span class="Identifier">mcTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;hasKeyEx&quot;</span>
  300. <span class="Keyword">static</span><span class="Punctuation">:</span>
  301. <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>
  302. <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>
  303. <span class="Comment"># Will now be true since we inserted a value</span>
  304. <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>
  305. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L200" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  306. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L200" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  307. </dd>
  308. </div>
  309. </div>
  310. <div id="inc-procs-all">
  311. <div id="inc,CacheCounter,int">
  312. <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>
  313. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  314. <dd>
  315. 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>.
  316. <p><strong class="examples_text">Example:</strong></p>
  317. <pre class="listing"><span class="Keyword">static</span><span class="Punctuation">:</span>
  318. <span class="Keyword">let</span> <span class="Identifier">counter</span> <span class="Operator">=</span> <span class="RawData">CacheCounter&quot;incTest&quot;</span>
  319. <span class="Identifier">inc</span> <span class="Identifier">counter</span>
  320. <span class="Identifier">inc</span> <span class="Identifier">counter</span><span class="Punctuation">,</span> <span class="DecNumber">5</span>
  321. <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>
  322. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L71" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  323. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L71" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  324. </dd>
  325. </div>
  326. </div>
  327. <div id="incl-procs-all">
  328. <div id="incl,CacheSeq,NimNode">
  329. <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>
  330. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  331. <dd>
  332. 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>
  333. 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>
  334. <p><strong class="examples_text">Example:</strong></p>
  335. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  336. <span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;inclTest&quot;</span>
  337. <span class="Keyword">static</span><span class="Punctuation">:</span>
  338. <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>
  339. <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>
  340. <span class="Comment"># still one element</span>
  341. <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>
  342. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L94" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  343. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L94" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  344. </dd>
  345. </div>
  346. </div>
  347. <div id="len-procs-all">
  348. <div id="len,CacheSeq">
  349. <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>
  350. <dd>
  351. Returns the length of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
  352. <p><strong class="examples_text">Example:</strong></p>
  353. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  354. <span class="Keyword">const</span> <span class="Identifier">mySeq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;lenTest&quot;</span>
  355. <span class="Keyword">static</span><span class="Punctuation">:</span>
  356. <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>
  357. <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>
  358. <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>
  359. <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>
  360. <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>
  361. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L109" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  362. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L109" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  363. </dd>
  364. </div>
  365. <div id="len,CacheTable">
  366. <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>
  367. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  368. <dd>
  369. Returns the number of elements in <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.
  370. <p><strong class="examples_text">Example:</strong></p>
  371. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  372. <span class="Keyword">const</span> <span class="Identifier">dataTable</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;lenTest&quot;</span>
  373. <span class="Keyword">static</span><span class="Punctuation">:</span>
  374. <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>
  375. <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>
  376. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L178" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  377. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L178" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  378. </dd>
  379. </div>
  380. </div>
  381. <div id="value-procs-all">
  382. <div id="value,CacheCounter">
  383. <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>
  384. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  385. <dd>
  386. Returns the value of a counter <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt>.
  387. <p><strong class="examples_text">Example:</strong></p>
  388. <pre class="listing"><span class="Keyword">static</span><span class="Punctuation">:</span>
  389. <span class="Keyword">let</span> <span class="Identifier">counter</span> <span class="Operator">=</span> <span class="RawData">CacheCounter&quot;valTest&quot;</span>
  390. <span class="Comment"># default value is 0</span>
  391. <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>
  392. <span class="Identifier">inc</span> <span class="Identifier">counter</span>
  393. <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>
  394. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L60" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  395. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L60" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  396. </dd>
  397. </div>
  398. </div>
  399. </dl>
  400. </div>
  401. <div class="section" id="15">
  402. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  403. <dl class="item">
  404. <div id="items-iterators-all">
  405. <div id="items.i,CacheSeq">
  406. <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>
  407. <dd>
  408. Iterates over each item in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>.
  409. <p><strong class="examples_text">Example:</strong></p>
  410. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  411. <span class="Keyword">const</span> <span class="Identifier">myseq</span> <span class="Operator">=</span> <span class="RawData">CacheSeq&quot;itemsTest&quot;</span>
  412. <span class="Keyword">static</span><span class="Punctuation">:</span>
  413. <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>
  414. <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>
  415. <span class="Keyword">for</span> <span class="Identifier">val</span> <span class="Keyword">in</span> <span class="Identifier">myseq</span><span class="Punctuation">:</span>
  416. <span class="Comment"># check that all values in `myseq` are int literals</span>
  417. <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>
  418. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L146" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  419. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L146" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  420. </dd>
  421. </div>
  422. </div>
  423. <div id="pairs-iterators-all">
  424. <div id="pairs.i,CacheTable">
  425. <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>
  426. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  427. <dd>
  428. 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>.
  429. <p><strong class="examples_text">Example:</strong></p>
  430. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">macros</span>
  431. <span class="Keyword">const</span> <span class="Identifier">mytabl</span> <span class="Operator">=</span> <span class="RawData">CacheTable&quot;values&quot;</span>
  432. <span class="Keyword">static</span><span class="Punctuation">:</span>
  433. <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>
  434. <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>
  435. <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>
  436. <span class="Comment"># make sure that we actually get the same keys</span>
  437. <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>
  438. <span class="Comment"># all vals are int literals</span>
  439. <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>
  440. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/core/macrocache.nim#L229" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  441. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/core/macrocache.nim#L229" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  442. </dd>
  443. </div>
  444. </div>
  445. </dl>
  446. </div>
  447. </div>
  448. </div>
  449. <div class="twelve-columns footer">
  450. <span class="nim-sprite"></span>
  451. <br>
  452. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-06 22:28:19 UTC</small>
  453. </div>
  454. </div>
  455. </div>
  456. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  457. </body>
  458. </html>