diff options
author | Juan Carlos <juancarlospaco@gmail.com> | 2021-08-08 14:26:34 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-08 19:26:34 +0200 |
commit | 2cddf7fc96a01bcd0f6029f38de005314333daca (patch) | |
tree | 1ddec4f677ee71341df94fabfff5386c5bcf21c0 | |
parent | 6563a685c1076cb5342f65d192b8f2a983220dba (diff) | |
download | Nim-2cddf7fc96a01bcd0f6029f38de005314333daca.tar.gz |
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>
-rw-r--r-- | doc/manual.rst | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/doc/manual.rst b/doc/manual.rst index 1b65ae9ee..41ed49715 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -5835,6 +5835,27 @@ type `system.ForLoopStmt` can rewrite the entirety of a `for` loop: 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" + + import std/macros + macro enumerate(x: ForLoopStmt): untyped = expectKind x, nnkForStmt # check if the starting count is specified: @@ -5866,7 +5887,6 @@ type `system.ForLoopStmt` can rewrite the entirety of a `for` loop: echo a, " ", b - Special Types ============= |