From 6a0d288cae9023e9b45cc67c28c331871e58eed5 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 15 Sep 2016 04:21:25 +0200 Subject: doc: tut2: simplify debug macro example --- doc/tut2.rst | 9 +++++---- 1 file 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] -- cgit 1.4.1-2-gfad0