Created
December 17, 2017 20:22
-
-
Save treeform/7a41296e7c341c10c97cfe6181c7fe4c to your computer and use it in GitHub Desktop.
This file contains 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