Is it possible to check if a function has been called with a keyword argument explicitly?

Is there a way to determine if a keyword argument with a default value has been explicitly given or the default has been used ?

function foo(;karg1::Int64=3)
    # if foo has been called with karg1 explicitly then... else...
end

I know I can use kwargs... and then check the dictionary, but my actual function has several default keyword arguments and I am interested in checking just one…

(I bet “no” but… never know!)

If I’m getting the jist of what you want. I think multiple dispatch with varied input defined as different functions should meet your requirements.

My suggestion here would allow this, but could be considered to make your function “messier”.

function A(x; karg1=nothing)
    if isnothing(karg1)
        karg1 = 3
    else
        # karg1 was explicitly given
    end
    # rest of function
end

And you could even disambiguate whether the keyword argument was explicitly given with the default value, e.g.

function A(x; karg1=nothing)
    if isnothing(karg1)
        karg1 = 3
    elseif karg1 == 3
        # karg1 was explicitly given as the default value
    end
    # rest of function
end

yep, that’s exactly the “solution” I ended up using…