Oh, right!  I guess it's testing it on untyped rather than the actual type in 
the macro. Anyways, this one is definitely working, it just tests for 
void-typed arguments:
    
    
    import macros
    import typetraits
    import strformat
    
    macro fun*(n: varargs[typed]): typed =
        result = newNimNode(nnkStmtList, n)
        var echoedCount = 0
        for x in n:
            if x.getTypeInst.typeKind != ntyVoid:
                result.add(newCall("echo", x))
                echoedCount += 1
        
        result.add(newCall("echo", newStrLitNode($(echoedCount))))
    
    proc bar() = echo "ok"
    
    fun(1+1) # n.len=1
    fun() # n.len=0
    # comment this to make it work
    fun(bar())
    
    

> isn't that a better behavior? if not what would be downsides of that?

No, I think automatically filtering void arguments in a macro is not a better 
or intuitive behavior. What if you remove a return type from a function and the 
compiler just silently starts ignoring it in argument lists instead of 
producing a type mismatch error? That seems like it could be an interesting 
source of bugs.

I guess what you're asking for is not SFINAE, but it feels similar -- it's a 
hack used to make template systems have some limited metaprogramming. I think 
that you'll find that sort of thing is not necessary with Nim, you can just 
write a macro that does what you want. Is there something specific that you're 
trying to do that requires the argument-ignoring approach used in D? Maybe we 
could help you come up with a good solution for it in Nim. 

Reply via email to