Keyword arguments confustion


function choose(a::Type{Val{:Gaussian},b::Type{Val{:Gamma}};
             data::Any = nothing,comp::Any=nothing)
print(1) 

And I want it to dispatch on symbols and I create the following shortcut

const choose(a::Symbol,b::Symbol,kwargs...) = choose(Val{a},Val{b},kwargs)

But calling choose(:Gaussian,:Gamma) is not dispatched to the first function since kwargs are mismatched… What is the correct way deal with the optional keyword arguments? It is mandatory to match the keywords?

I think const doesn’t make sense in this context. And then you have to splat the kwargs you slurped.
And Val{b} is a type, you want Val(b).

choose(a::Symbol,b::Symbol,kwargs...) = choose(Val(a),Val(b),kwargs...)
1 Like

It does not work.

You need to splat kwargs… at the end.

But it feels like you there may be an alternative way of doing this - maybe some kind of dictionary?

Right. You also need to seperate the kwargs via ;

choose(a::Symbol,b::Symbol;kwargs...) = choose(Val(a),Val(b);kwargs...)
3 Likes