Why Can not My Recursive Function Work?

Executing your code I get

julia> add_Varargs(xx...)
3
2
ERROR: MethodError: no method matching +(::Int64, ::Tuple{Int64})

So it works at the beginning but fails on the + with the last call, because it cannot add an integer to a tuple. Why is it trying to add a tuple? It’s here:

    if length(b) == 1
        return b
    end

This returns a tuple of length 1 instead of a number.

2 Likes