I guess that D has implemented some kind of SFINAE that won't run for args that 
cause errors? Since Nim has a full macro system, it doesn't need those sorts of 
things, but you can certainly emulate the behavior. Use the proc compiles, 
which will return true if an expression compiles without errors:
    
    
    macro fun*(n: varargs[untyped]): typed =
        result = newNimNode(nnkStmtList, n)
        var echoedCount = 0
        for x in n:
            if compiles(echo(x)):
                result.add(newCall("echo", x))
                echoedCount += 1
        
        result.add(newCall("echo", newStrLitNode($(echoedCount))))
    
    proc bar() = echo "ok"
    
    

Reply via email to