It works when the macro parameter is untyped, I guess constant folding happens 
during the typing process:
    
    
    import macros
    
    macro mylog(x:untyped): untyped =
        result = newNimNode(nnkStmtList, x)
        result.add(newCall("write", newIdentNode("stdout"), toStrLit(x)))
        result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(":")))
        result.add(newCall("writeLine", newIdentNode("stdout"), x))
    
    var x=1
    mylog(x+1) # x + 1:2  (OK but I'd rather want exact source code with 
spacing eg: `x+1:2`)
    mylog(1+1) # 2:2 (not OK, I want: 1+1: 2)
    

Reply via email to