Documentation only, add 1 example (#18621)
* ReSync with Devel * ReSync * Documentation only, add 1 example to For loop macro * Flip it * Update doc/manual.rst Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
parent
6563a685c1
commit
2cddf7fc96
1 changed files with 21 additions and 1 deletions
|
|
@ -5830,6 +5830,27 @@ For loop macro
|
|||
A macro that takes as its only input parameter an expression of the special
|
||||
type `system.ForLoopStmt` can rewrite the entirety of a `for` loop:
|
||||
|
||||
.. code-block:: nim
|
||||
:test: "nim c $1"
|
||||
|
||||
import std/macros
|
||||
|
||||
macro example(loop: ForLoopStmt) =
|
||||
result = newTree(nnkForStmt) # Create a new For loop.
|
||||
result.add loop[^3] # This is "item".
|
||||
result.add loop[^2][^1] # This is "[1, 2, 3]".
|
||||
result.add newCall(bindSym"echo", loop[0])
|
||||
|
||||
for item in example([1, 2, 3]): discard
|
||||
|
||||
Expands to:
|
||||
|
||||
.. code-block:: nim
|
||||
for item in items([1, 2, 3]):
|
||||
echo item
|
||||
|
||||
Another example:
|
||||
|
||||
.. code-block:: nim
|
||||
:test: "nim c $1"
|
||||
|
||||
|
|
@ -5866,7 +5887,6 @@ type `system.ForLoopStmt` can rewrite the entirety of a `for` loop:
|
|||
echo a, " ", b
|
||||
|
||||
|
||||
|
||||
Special Types
|
||||
=============
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue