Concise call keyword arg with default by conditional

I tried to show an example below. This might be a bit persnickety, but it seems like it would be nice to have a cleaner solution for this situation.

I have function A with a keyword argument that specifies a default value. I have an “in between” function B that receives a value and calls function A with that value. However, if that value is nothing, it should use the default value. Is there some way to code this without what seems like redundancy?

Either I have to write a conditional at the call site, or have function A have both a default value for the argument (I need that for other cases) and convert a nothing value to that default value inside the function.

function test(x; kwarg=100)
  println(x, ' ', arg2)
end

a = nothing

# How to remove the conditional so it uses default value for kwarg?
isnothing(a) ? test(17) : test(17; kwarg=a)

Interesting problem. Not at a computer right now, but does test(17; (isnothing(a) ? (; kwarg=a) : (;))...) do anything?

The latter is the idiomatic/Julian solution: assign kwarg=nothing in the signature, and in the function body, and set kwarg to its default value if isnothing(kwarg). nothing serves as an “unset” sentinel value that doesn’t special case a regular value (e.g. using -1 as the “unset” value). nothing could even still be used as a valid value by giving the kwarg as Some(nothing).

function A(x; kwarg=nothing)
    if isnothing(kwarg)
        kwarg = 100
    end
    # rest of function
end