2 ms·
You can also do this (in case that's any clearer): template debugImpl(varName, value: typed) = stdout.write(varName) stdout.write(": ") s
by dom96 10y ago
You can also do this (in case that's any clearer):
template debugImpl(varName, value: typed) =
stdout.write(varName)
stdout.write(": ")
stdout.writeLine(x)
macro debug(n: varargs[expr]): stmt =
result = newNimNode(nnkStmtList, n)
for x in n:
result.add(getAst(debugImpl(toStrLit(x), x)))
Whether the Lisp version is clearer or not is very subjective, and you obviously have a lot more experience with it so of course it's clearer for you. To me, the Nim version is far clearer.
Edit: flyx's version is even better!
- qwertyuiop924 10y agoI am aware that a template would work in this case (it would also do so in Scheme, but templates are generally less powerful, and I was making a point about imperative macro systems). And yeah, that mixture of templates and macros that you used is semantically similar to what my Scheme code did. But I find Nim discourages writing small templates, which I find myself doing a lot when writing macros in Scheme. Personally, I find that Nim less confusing but still quite awkward.