summary refs log tree commit diff stats
path: root/doc/tut2.rst
diff options
context:
space:
mode:
authorSimon Ruderich <simon@ruderich.org>2016-09-15 04:21:25 +0200
committerSimon Ruderich <simon@ruderich.org>2016-09-15 11:43:57 +0200
commit6a0d288cae9023e9b45cc67c28c331871e58eed5 (patch)
treef61d7718c9f97957c9059497af36be06defa3a02 /doc/tut2.rst
parent21433477df28ab1078c15bbd20c12fd313a7fdb8 (diff)
downloadNim-6a0d288cae9023e9b45cc67c28c331871e58eed5.tar.gz
doc: tut2: simplify debug macro example
Diffstat (limited to 'doc/tut2.rst')
-rw-r--r--doc/tut2.rst9
1 files changed, 5 insertions, 4 deletions
diff --git a/doc/tut2.rst b/doc/tut2.rst
index 3f94325ff..845feb6d1 100644
--- a/doc/tut2.rst
+++ b/doc/tut2.rst
@@ -674,17 +674,18 @@ variable number of arguments:
 
   macro debug(n: varargs[expr]): stmt =
     # `n` is a Nim AST that contains a list of expressions;
-    # this macro returns a list of statements:
+    # this macro returns a list of statements (n is passed for proper line
+    # information):
     result = newNimNode(nnkStmtList, n)
     # iterate over any argument that is passed to this macro:
-    for i in 0..n.len-1:
+    for x in n:
       # add a call to the statement list that writes the expression;
       # `toStrLit` converts an AST to its string representation:
-      result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i])))
+      result.add(newCall("write", newIdentNode("stdout"), toStrLit(x)))
       # add a call to the statement list that writes ": "
       result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(": ")))
       # add a call to the statement list that writes the expressions value:
-      result.add(newCall("writeLine", newIdentNode("stdout"), n[i]))
+      result.add(newCall("writeLine", newIdentNode("stdout"), x))
 
   var
     a: array[0..10, int]