# Splatting extra keyword arguments?

**URL:** <https://discourse.julialang.org/t/splatting-extra-keyword-arguments/25423>\
**Category:** Internals & Design\
**Created:** [June 18, 2019, 8:11pm UTC](https://discourse.julialang.org/t/splatting-extra-keyword-arguments/25423 "2019-06-18T20:11:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dstarerstor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dstarerstor/32/8958_2.png) [@dstarerstor](https://discourse.julialang.org/u/dstarerstor)\
**Post date:** [June 18, 2019, 8:11pm UTC](https://discourse.julialang.org/t/splatting-extra-keyword-arguments/25423/1 "2019-06-18T20:11:27Z")

</div>

I recently tried to splat a collection of extra keyword arguments from one function into another and found it very weird that they are interpreted as non-keyword argument pairs by the second function. For example, take the following

```julia
function foo(args... ; kwargs...)
    for i in args
        println("This is an arg: ", i)
    end
    for j in kwargs
        println("This is a kwarg: ", j)
    end
    return args, kwargs
end

a, b = foo(1, 2 , c=3, d=4) #works as expected
foo(a... , b...) #prints all as args, none as kwargs

```

I get it, but I find it very counter intuitive. Is there a reason that a Pair{Symbol, Any} shouldn’t be interpreted as a keyword argument (assuming the method allows keyword arguments)?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [June 18, 2019, 8:13pm UTC](https://discourse.julialang.org/t/splatting-extra-keyword-arguments/25423/2 "2019-06-18T20:13:43Z")

</div>

`foo(a...; b...)` forces `b...` to be interpreted as kwargs – `Pair{Symbol, Any}` is a perfectly valid input type, so you need some syntactical difference between splattin positional args and kwargs.

---

<div class="post-metadata">

**Author:** ![dstarerstor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dstarerstor/32/8958_2.png) [@dstarerstor](https://discourse.julialang.org/u/dstarerstor)\
**Post date:** [June 18, 2019, 8:22pm UTC](https://discourse.julialang.org/t/splatting-extra-keyword-arguments/25423/3 "2019-06-18T20:22:02Z")

</div>

I guess my meaning is that every keyword argument is essentially a `Pair{Symbol,Any}` so I would expect Julia to use the method that has keyword arguments if I pass a `Pair{Symbol,Any}`, similar to how it prefers a method that has specified types if the argument types match. At the very least I would expect it not to throw an error if I splat into a function that only has keyword arguments

---

<div class="post-metadata">

**Author:** ![dellison](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dellison](https://discourse.julialang.org/u/dellison)\
**Post date:** [June 18, 2019, 8:51pm UTC](https://discourse.julialang.org/t/splatting-extra-keyword-arguments/25423/4 "2019-06-18T20:51:51Z")

</div>

I don’t think I have much to add, but in case you haven’t seen this section before, there’s some good explanation of how Julia’s keyword arguments work in the manual [here](https://docs.julialang.org/en/v1/manual/functions/index.html#Keyword-Arguments-1).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 19, 2019, 4:19am UTC](https://discourse.julialang.org/t/splatting-extra-keyword-arguments/25423/5 "2019-06-19T04:19:39Z")

</div>

> [@dstarerstor](#):
>
> so I would expect Julia to use the method that has keyword arguments if I pass a `Pair{Symbol,Any}` , similar to how it prefers a method that has specified types if the argument types match

That is not how it works, keyword arguments are treated separately from positional ones. This happens as code is parsed, and has nothing to do with dispatch.
