> bar returns nothing, how could you echo it. I see nothing to fix here, 
> especially not the involved lengths.

if nim treated a void-returning function call as being 0 arguments as in D (as 
if no argument was passed) then there would be no call to echo (ie, fun(bar()) 
would call bar() and then fun()) ; this introduces less edge cases (no need to 
consider void variables). Maybe I'm missing some valid use case I haven't 
thought about?

> I guess that D has implemented some kind of SFINAE that won't run for args 
> that cause errors?

no, it's simpler than that: as I was explaining above, in D, variadic argument 
size will be 0 when calling fun(bar()); since bar returns void

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

> it doesn't need those sorts of things, but you can certainly emulate the 
> behavior.

your code doesn't work, compiles(echo(x)) still returns true; here's a full 
modified example so you can click run:
    
    
    import macros
    import typetraits
    import strformat
    
    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"
    
    fun(1+1) # n.len=1
    fun() # n.len=0
    # comment this to make it work
    fun(bar())
    

Reply via email to