Created
January 23, 2018 23:11
-
-
Save treeform/929915fae3ce5923df69e940d2b657c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import macros | |
| macro print*(n: varargs[typed]): untyped = | |
| result = newNimNode(nnkStmtList, n) | |
| for i in 0..n.len-1: | |
| if n[i].kind == nnkStrLit: | |
| # pure string literals are written diretly | |
| result.add(newCall("write", newIdentNode("stdout"), n[i])) | |
| else: | |
| # other expressions are written in <expression>: <value> syntax | |
| result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i]))) | |
| result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(": "))) | |
| result.add(newCall("write", newIdentNode("stdout"), n[i])) | |
| if i != n.len-1: | |
| # separate by " " | |
| result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(" "))) | |
| else: | |
| # add newline | |
| result.add(newCall("writeLine", newIdentNode("stdout"), newStrLitNode(""))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I this might solves my problem