# Keyword arguments confustion

**URL:** <https://discourse.julialang.org/t/keyword-arguments-confustion/28470>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 6, 2019, 2:41pm UTC](https://discourse.julialang.org/t/keyword-arguments-confustion/28470 "2019-09-06T14:41:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonsun0310](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jasonsun0310/32/10082_2.png) [@jasonsun0310](https://discourse.julialang.org/u/jasonsun0310)\
**Post date:** [September 6, 2019, 2:41pm UTC](https://discourse.julialang.org/t/keyword-arguments-confustion/28470/1 "2019-09-06T14:41:35Z")

</div>

```julia

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

```julia
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?

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [September 6, 2019, 2:55pm UTC](https://discourse.julialang.org/t/keyword-arguments-confustion/28470/2 "2019-09-06T14:55:19Z")

</div>

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)`.

```julia
choose(a::Symbol,b::Symbol,kwargs...) = choose(Val(a),Val(b),kwargs...)

```

---

<div class="post-metadata">

**Author:** ![jasonsun0310](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jasonsun0310/32/10082_2.png) [@jasonsun0310](https://discourse.julialang.org/u/jasonsun0310)\
**Post date:** [September 6, 2019, 3:12pm UTC](https://discourse.julialang.org/t/keyword-arguments-confustion/28470/3 "2019-09-06T15:12:39Z")

</div>

It does not work.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [September 6, 2019, 3:31pm UTC](https://discourse.julialang.org/t/keyword-arguments-confustion/28470/4 "2019-09-06T15:31:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [September 6, 2019, 7:45pm UTC](https://discourse.julialang.org/t/keyword-arguments-confustion/28470/5 "2019-09-06T19:45:35Z")

</div>

Right. You also need to seperate the kwargs via `;`

```julia
choose(a::Symbol,b::Symbol;kwargs...) = choose(Val(a),Val(b);kwargs...)

```
