diff options
author | Vindaar <basti90@gmail.com> | 2018-08-31 01:16:44 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-31 01:16:44 +0200 |
commit | 47c7fd037ed28b7de3d120b003d059d30e18f128 (patch) | |
tree | 2b6cdb1e26839c7640f6d9bf4c259d60481d6184 | |
parent | 2f7b979e384ff6cc750e123939401a72c3f59093 (diff) | |
download | Nim-47c7fd037ed28b7de3d120b003d059d30e18f128.tar.gz |
Improve enumerate macro (#8819)
* fix case macro manual entry to produce code block Previously line breaks were so weird that the code blocks were not created. * improve `enumerate` for loop macro by wrapping in block
-rw-r--r-- | doc/manual.rst | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/doc/manual.rst b/doc/manual.rst index 29671d3dd..b2d66f684 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -5459,12 +5459,17 @@ type ``system.ForLoopStmt`` can rewrite the entirety of a ``for`` loop: newFor.add x[^2][1] newFor.add body result.add newFor + # now wrap the whole macro in a block to create a new scope + result = quote do: + block: `result` for a, b in enumerate(items([1, 2, 3])): echo a, " ", b - for a2, b2 in enumerate([1, 2, 3, 5]): - echo a2, " ", b2 + # without wrapping the macro in a block, we'd need to choose different + # names for `a` and `b` here to avoid redefinition errors + for a, b in enumerate([1, 2, 3, 5]): + echo a, " ", b Currently for loop macros must be enabled explicitly @@ -5474,12 +5479,11 @@ via ``{.experimental: "forLoopMacros".}``. Case statement macros --------------------- -A macro that needs to be called `match`:idx: can be used to -rewrite ``case`` statements in order to -implement `pattern matching`:idx: for certain types. The following -example implements a simplistic form of pattern matching for tuples, -leveraging the existing equality operator for tuples (as provided in - ``system.==``): +A macro that needs to be called `match`:idx: can be used to rewrite +``case`` statements in order to implement `pattern matching`:idx: for +certain types. The following example implements a simplistic form of +pattern matching for tuples, leveraging the existing equality operator +for tuples (as provided in ``system.==``): .. code-block:: nim :test: "nim c $1" |