summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorhlaaftana <10591326+hlaaftana@users.noreply.github.com>2021-02-08 21:35:06 +0300
committerGitHub <noreply@github.com>2021-02-08 19:35:06 +0100
commit6a7baff97dd0800712b60b7b685ff23f66b9d127 (patch)
tree127dabe830ba5498471e90f3bdc241960e0122f8 /doc
parentabac35e7437dd1ac2b3687dfa51de7f9d4b6e853 (diff)
downloadNim-6a7baff97dd0800712b60b7b685ff23f66b9d127.tar.gz
rename case statement macro from match to `case` (#16923)
* rename case statement macro from match to `case`

* fix test
Diffstat (limited to 'doc')
-rw-r--r--doc/manual_experimental.rst24
1 files changed, 11 insertions, 13 deletions
diff --git a/doc/manual_experimental.rst b/doc/manual_experimental.rst
index 02602d98d..63108c896 100644
--- a/doc/manual_experimental.rst
+++ b/doc/manual_experimental.rst
@@ -947,11 +947,10 @@ the documentation of `spawn <#parallel-amp-spawn-spawn-statement>`_ for details.
 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.==``):
+Macros named `case` can rewrite `case` statements for certain types in order to
+implement `pattern matching`:idx:. 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"
@@ -960,7 +959,7 @@ for tuples (as provided in ``system.==``):
 
   import macros
 
-  macro match(n: tuple): untyped =
+  macro `case`(n: tuple): untyped =
     result = newTree(nnkIfStmt)
     let selector = n[0]
     for i in 1 ..< n.len:
@@ -973,8 +972,7 @@ for tuples (as provided in ``system.==``):
           let cond = newCall("==", selector, it[j])
           result.add newTree(nnkElifBranch, cond, it[^1])
       else:
-        error "'match' cannot handle this node", it
-    echo repr result
+        error "custom 'case' for tuple cannot handle this node", it
 
   case ("foo", 78)
   of ("foo", 78): echo "yes"
@@ -985,12 +983,12 @@ for tuples (as provided in ``system.==``):
 Currently case statement macros must be enabled explicitly
 via ``{.experimental: "caseStmtMacros".}``.
 
-``match`` macros are subject to overload resolution. First the
-``case``'s selector expression is used to determine which ``match``
-macro to call. To this macro is then passed the complete ``case``
-statement body and the macro is evaluated.
+`case` macros are subject to overload resolution. The type of the
+`case` statement's selector expression is matched against the type
+of the first argument of the `case` macro. Then the complete `case`
+statement is passed in place of the argument and the macro is evaluated.
 
-In other words, the macro needs to transform the full ``case`` statement
+In other words, the macro needs to transform the full `case` statement
 but only the statement's selector expression is used to determine which
 macro to call.